Code::Blocks Forums

User forums => General (but related to Code::Blocks) => Topic started by: thanhbuu on May 18, 2012, 03:38:54 pm

Title: file in subject
Post by: 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) ?
Title: Re: file in subject
Post by: stahta01 on May 18, 2012, 06:38:52 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.
Title: Re: file in subject
Post by: 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!
Title: Re: file in subject
Post by: stahta01 on May 18, 2012, 10:11:07 pm
Try looking under
"Project" -> "Properties"
Tab: "Build Targets"

I do not have the time to write directions.

Tim S.
Title: Re: file in subject
Post by: thanhbuu on May 19, 2012, 05:56:10 am
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?
Title: Re: file in subject
Post by: oBFusCATed on May 19, 2012, 08:23:19 am
Add the different files in two+ different targets...
Title: Re: file in subject
Post by: thanhbuu on May 19, 2012, 10:17:37 am
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.
Title: Re: file in subject
Post by: oBFusCATed on May 19, 2012, 10:22:00 am
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...
Title: Re: file in subject
Post by: thanhbuu on May 19, 2012, 11:02:37 am
I did as this tutorial to make two targets: http://wiki.codeblocks.org/index.php?title=Creating_a_new_project (http://wiki.codeblocks.org/index.php?title=Creating_a_new_project) but it shows this error:

Code
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?
Title: Re: file in subject
Post by: oBFusCATed on May 19, 2012, 11:21:10 am
Remove the option...
Title: Re: file in subject
Post by: thanhbuu on May 19, 2012, 11:24:53 am
again it shows "multiple definition of `main'"
Title: Re: file in subject
Post by: oBFusCATed on May 19, 2012, 11:36:04 am
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!
Title: Re: file in subject
Post by: stahta01 on May 19, 2012, 04:02:28 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.
Title: Re: file in subject
Post by: Jenna on May 19, 2012, 04:34:31 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.
Title: Re: file in subject
Post by: thanhbuu on May 19, 2012, 04:47:47 pm
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!