News:

Accounts with zero posts and zero activity during the last months will be deleted periodically to fight SPAM!

Main Menu

file in subject

Started by thanhbuu, May 18, 2012, 03:38:54 PM

Previous topic - Next topic

thanhbuu

can C::B add two file *.cpp but compile indepently because CB often ask if there were two "int main()" (even in separate two files) ?

stahta01

Quote from: thanhbuu on May 18, 2012, 03:38:54 PM
can C::B add two file *.cpp but compile indepently because CB often ask if there were two "int main()" (even in separate two files) ?

Yes, the CB Project has more than one main in it. But, each target can have at most a single main in it.

Tim S.
C Programmer working to learn more about C++.
On Windows 10 64 bit and Windows 11 64 bit.
--
When in doubt, read the CB WiKi FAQ. [url="http://wiki.codeblocks.org"]http://wiki.codeblocks.org[/url]

thanhbuu

how can I do it? Please give me some detail if I want to build/debug a file? Thanks!

stahta01

#3
Try looking under
"Project" -> "Properties"
Tab: "Build Targets"

I do not have the time to write directions.

Tim S.
C Programmer working to learn more about C++.
On Windows 10 64 bit and Windows 11 64 bit.
--
When in doubt, read the CB WiKi FAQ. [url="http://wiki.codeblocks.org"]http://wiki.codeblocks.org[/url]

thanhbuu

Sorry but as I can see the "Build Target" is just Debug or Release. It doesn't give me a chance to select which file I need to debug step by step :) So how can I?

oBFusCATed

Add the different files in two+ different targets...
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

thanhbuu

I don't get what you mean (in "two" what?). It always shows the error "multiple definition of `main'". How can I fix this using TWO file in ONE subject? That's what I mean.

oBFusCATed

What is subject in you language?
In C::B's terms we use 'project'.

What I've ment was:
1. Create a project
2. Create two targets
3. Add the first file to target1
4. Add the second file to target2
5. Build target1 or target2
6. Add virtual target to combine the two targets, so they get built together...

The same can be done with two separate projects...
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

thanhbuu

I did as this tutorial to make two targets: http://wiki.codeblocks.org/index.php?title=Creating_a_new_project but it shows this error:

mingw32-g++.exe: error: unrecognized option '-shared-libstdc++'
Process terminated with status 1 (0 minutes, 0 seconds)
0 errors, 0 warnings (0 minutes, 0 seconds)

how can I fix it?

oBFusCATed

(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

thanhbuu

again it shows "multiple definition of `main'"

oBFusCATed

Then you have two main functions in two files compiled together.

Please read this: http://wiki.codeblocks.org/index.php?title=FAQ-Compiling_%28errors%29#Q:_How_do_I_troubleshoot_a_compiler_problem.3F
And make sure you understand it!
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

stahta01

Quote from: thanhbuu on May 18, 2012, 06:40:51 PM
how can I do it? Please give me some detail if I want to build/debug a file? Thanks!

The fastest way is to use a separate project for each file; that will work for you.

My answer of using separate targets was to your original question (of compiling two files with main in each); I have no idea if debugging will work right with separate targets.

Tim S.
C Programmer working to learn more about C++.
On Windows 10 64 bit and Windows 11 64 bit.
--
When in doubt, read the CB WiKi FAQ. [url="http://wiki.codeblocks.org"]http://wiki.codeblocks.org[/url]

Jenna

Quote from: stahta01 on May 19, 2012, 04:02:28 PM
Quote from: thanhbuu on May 18, 2012, 06:40:51 PM
how can I do it? Please give me some detail if I want to build/debug a file? Thanks!

The fastest way is to use a separate project for each file; that will work for you.

My answer of using separate targets was to your original question (of compiling two files with main in each); I have no idea if debugging will work right with separate targets.

Tim S.
If the compiler-settings are correct, it will work, because you can debug one target and ignore the other one.

thanhbuu

Anybody can do this (according to the tutorial as I mentioned or by your experience), can you post a video of the process so that everybody know this process? Thanks!