Code::Blocks Forums

User forums => Using Code::Blocks => Topic started by: wzyjy on December 14, 2010, 03:03:14 pm

Title: Multiple definition during linking console executable
Post by: wzyjy 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!
Title: Re: Multiple definition during linking console executable
Post by: wzyjy 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

Title: Re: Multiple definition during linking console executable
Post by: oBFusCATed on December 14, 2010, 03:29:33 pm
You're including some .cc aren't you?
Title: Re: Multiple definition during linking console executable
Post by: wzyjy 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...
Title: Re: Multiple definition during linking console executable
Post by: wzyjy 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?
Title: Re: Multiple definition during linking console executable
Post by: Jenna 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.
Title: Re: Multiple definition during linking console executable
Post by: wzyjy 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.
Title: Re: Multiple definition during linking console executable
Post by: reckless on December 14, 2010, 05:05:41 pm
can easily get around it by supplying -Wl,--allow-multiple-definition to the linker flags.

Title: Re: Multiple definition during linking console executable
Post by: wzyjy 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?
Title: Re: Multiple definition during linking console executable
Post by: oBFusCATed 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
Title: Re: Multiple definition during linking console executable
Post by: wzyjy 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.
Title: Re: Multiple definition during linking console executable
Post by: Jenna 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.
Title: Re: Multiple definition during linking console executable
Post by: reckless 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.