Author Topic: file in subject  (Read 7057 times)

Offline thanhbuu

  • Multiple posting newcomer
  • *
  • Posts: 24
file in subject
« 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) ?
« Last Edit: May 18, 2012, 04:46:06 pm by thanhbuu »

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7582
    • My Best Post
Re: file in subject
« Reply #1 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.
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline thanhbuu

  • Multiple posting newcomer
  • *
  • Posts: 24
Re: file in subject
« Reply #2 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!

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7582
    • My Best Post
Re: file in subject
« Reply #3 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.
« Last Edit: May 18, 2012, 10:13:00 pm by stahta01 »
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline thanhbuu

  • Multiple posting newcomer
  • *
  • Posts: 24
Re: file in subject
« Reply #4 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?

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: file in subject
« Reply #5 on: May 19, 2012, 08:23:19 am »
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!]

Offline thanhbuu

  • Multiple posting newcomer
  • *
  • Posts: 24
Re: file in subject
« Reply #6 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.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: file in subject
« Reply #7 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...
(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!]

Offline thanhbuu

  • Multiple posting newcomer
  • *
  • Posts: 24
Re: file in subject
« Reply #8 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 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?

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: file in subject
« Reply #9 on: May 19, 2012, 11:21:10 am »
Remove the option...
(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!]

Offline thanhbuu

  • Multiple posting newcomer
  • *
  • Posts: 24
Re: file in subject
« Reply #10 on: May 19, 2012, 11:24:53 am »
again it shows "multiple definition of `main'"

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: file in subject
« Reply #11 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!
(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!]

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7582
    • My Best Post
Re: file in subject
« Reply #12 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.
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7255
Re: file in subject
« Reply #13 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.

Offline thanhbuu

  • Multiple posting newcomer
  • *
  • Posts: 24
Re: file in subject
« Reply #14 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!