News:

The new Release 25.03 is out! You can download binaries for Windows and many major Linux distros here .

Main Menu

Multiple definition during linking console executable

Started by wzyjy, December 14, 2010, 03:03:14 PM

Previous topic - Next topic

wzyjy

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.:

Quoteobj/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!

wzyjy

PS: it even includes the main function:

Quoteobj/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


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!]

wzyjy


wzyjy

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?

Jenna

It looks like you try to compile a project, that has multiple sorce files, that declare a main-function.

wzyjy

Quote from: jens 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.

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.

reckless

can easily get around it by supplying -Wl,--allow-multiple-definition to the linker flags.


wzyjy

Quote from: reckless on December 14, 2010, 05:05: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?

oBFusCATed

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!]

wzyjy

Quote from: oBFusCATed on December 14, 2010, 05:25:25 PM
create one project with multiple targets (see the codeblocks.cbp file)

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

Jenna

Quote from: wzyjy on December 14, 2010, 05:15:45 PM
Quote from: reckless on December 14, 2010, 05:05: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.

reckless

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.