Author Topic: Multiple definition during linking console executable  (Read 15202 times)

Offline wzyjy

  • Single posting newcomer
  • *
  • Posts: 9
Multiple definition during linking console executable
« on: December 14, 2010, 03:03:14 pm »
I was trying to build a project, there's no error during the compilation, but during the process of linking console executable, it kept telling me "multiple definition of ...", e.g.:

Quote
obj/Debug/applications/binarize.o: In function `usage()':
/home/brianw/IRTKsrc/geometry++/include/irtkPoint.h:238: multiple definition of `input_name'
obj/Debug/applications/AnisoDiff.o:/home/brianw/IRTKsrc/applications/AnisoDiff.cc:14: first defined here

obj/Debug/applications/blur.o: In function `usage()':
/home/brianw/IRTKsrc/geometry++/include/irtkPoint.h:238: multiple definition of `input_name'
obj/Debug/applications/AnisoDiff.o:/home/brianw/IRTKsrc/applications/AnisoDiff.cc:14: first defined here

obj/Debug/applications/closing.o: In function `usage()':
/home/brianw/IRTKsrc/geometry++/include/irtkPoint.h:238: multiple definition of `input_name'
obj/Debug/applications/AnisoDiff.o:/home/brianw/IRTKsrc/applications/AnisoDiff.cc:14: first defined here

Can anyone help me with this? Thanks a lot!

Offline wzyjy

  • Single posting newcomer
  • *
  • Posts: 9
Re: Multiple definition during linking console executable
« Reply #1 on: December 14, 2010, 03:06:40 pm »
PS: it even includes the main function:

Quote
obj/Debug/applications/binarize.o: In function `main':
/home/brianw/IRTKsrc/applications/binarize.cc:25: multiple definition of `main'
obj/Debug/applications/AnisoDiff.o:/home/brianw/IRTKsrc/applications/AnisoDiff.cc:29: first defined here

obj/Debug/applications/blur.o: In function `main':
/home/brianw/IRTKsrc/applications/blur.cc:31: multiple definition of `main'
obj/Debug/applications/AnisoDiff.o:/home/brianw/IRTKsrc/applications/AnisoDiff.cc:29: first defined here

obj/Debug/applications/closing.o: In function `main':
/home/brianw/IRTKsrc/applications/closing.cc:29: multiple definition of `main'
obj/Debug/applications/AnisoDiff.o:/home/brianw/IRTKsrc/applications/AnisoDiff.cc:29: first defined here


Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Multiple definition during linking console executable
« Reply #2 on: December 14, 2010, 03:29:33 pm »
You're including some .cc aren't you?
(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 wzyjy

  • Single posting newcomer
  • *
  • Posts: 9
Re: Multiple definition during linking console executable
« Reply #3 on: December 14, 2010, 03:44:35 pm »
You're including some .cc aren't you?

you mean in the source code? I don't think so...

Offline wzyjy

  • Single posting newcomer
  • *
  • Posts: 9
Re: Multiple definition during linking console executable
« Reply #4 on: December 14, 2010, 03:49:12 pm »
I forgot to mention: if I just use the Makefile in the source code and do make in the terminal, it successfully generates executables, so I was wondering if this has anything to do with the setting of the IDE?

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7255
Re: Multiple definition during linking console executable
« Reply #5 on: December 14, 2010, 04:28:11 pm »
It looks like you try to compile a project, that has multiple sorce files, that declare a main-function.

Offline wzyjy

  • Single posting newcomer
  • *
  • Posts: 9
Re: Multiple definition during linking console executable
« Reply #6 on: December 14, 2010, 04:53:53 pm »
It looks like you try to compile a project, that has multiple sorce files, that declare a main-function.

maybe that's the problem, but please correct me if I'm wrong, this whole source code package would generate several executables, and for each one, is it suppose to be one corresponding main-function?

And why this is not a problem if I just use the makefile under the command line? - I just switched from Windows to Linux, so really not sure about how the makefile works.

Offline reckless

  • Regular
  • ***
  • Posts: 338
Re: Multiple definition during linking console executable
« Reply #7 on: December 14, 2010, 05:05:41 pm »
can easily get around it by supplying -Wl,--allow-multiple-definition to the linker flags.


Offline wzyjy

  • Single posting newcomer
  • *
  • Posts: 9
Re: Multiple definition during linking console executable
« Reply #8 on: December 14, 2010, 05:15:45 pm »
can easily get around it by supplying -Wl,--allow-multiple-definition to the linker flags.



Sorry I just started to use C:B but could you clarify how exactly I can do that, please?

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Multiple definition during linking console executable
« Reply #9 on: December 14, 2010, 05:25:25 pm »
wzyjy: one target can create only one executable/library

You have two solutions:
1. create one project with multiple targets (see the codeblocks.cbp file)
2. create multiple projects and add them to a workspace
(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 wzyjy

  • Single posting newcomer
  • *
  • Posts: 9
Re: Multiple definition during linking console executable
« Reply #10 on: December 14, 2010, 05:30:11 pm »
create one project with multiple targets (see the codeblocks.cbp file)

Could you please tell me how I can do this? Thanks.

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7255
Re: Multiple definition during linking console executable
« Reply #11 on: December 14, 2010, 05:30:41 pm »
can easily get around it by supplying -Wl,--allow-multiple-definition to the linker flags.



Sorry I just started to use C:B but could you clarify how exactly I can do that, please?
If you have multiple definitions of main, this will most likely not help.

You will not be able to get a working executable.

Maybe you should buy you a good book about programming, or search the web for a good tutorial.
If you do not understand what you do, you will never be able to make it work.

Offline reckless

  • Regular
  • ***
  • Posts: 338
Re: Multiple definition during linking console executable
« Reply #12 on: December 14, 2010, 08:25:46 pm »
my bad didnt notice the part with multiple main.

in that case aye it will most probably not work.

but for reference the -Wl,--allow-multiple-definition goes in build options/linker settings/other linker options.