Code::Blocks Forums
User forums => Using Code::Blocks => Topic started 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.:
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!
-
PS: it even includes the main function:
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
-
You're including some .cc aren't you?
-
You're including some .cc aren't you?
you mean in the source code? I don't think so...
-
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?
-
It looks like you try to compile a project, that has multiple sorce files, that declare a main-function.
-
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.
-
can easily get around it by supplying -Wl,--allow-multiple-definition to the linker flags.
-
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?
-
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
-
create one project with multiple targets (see the codeblocks.cbp file)
Could you please tell me how I can do this? Thanks.
-
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.
-
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.