Guide to fix multiple definiton linker issue

trilader

13-06-2010 19:57:06

After having problems building Hydrax because of linker issues I fou8nd out that die Code::Blocks project for Hydrax is messed up ands needs fixing:
With the default settings you get a lot of errors:

Linking dynamic library: bin\Release\Hydrax.dll
obj\Release\src\Hydrax\hydrax.o:Hydrax.cpp:(.text+0x0): multiple definition of `Hydrax::Hydrax::isComponent(Hydrax::HydraxComponent const&)'
Creating library file: bin\Release\libHydrax.a
obj\Release\src\Hydrax\Hydrax.o:Hydrax.cpp:(.text+0x0): first defined here
obj\Release\src\Hydrax\hydrax.o:Hydrax.cpp:(.text+0x38): multiple definition of `Hydrax::Hydrax::setPlanesError(float const&)'
obj\Release\src\Hydrax\Hydrax.o:Hydrax.cpp:(.text+0x38): first defined here
obj\Release\src\Hydrax\hydrax.o:Hydrax.cpp:(.text+0x7c): multiple definition of `Hydrax::Hydrax::setCausticsEnd(float const&)'
obj\Release\src\Hydrax\Hydrax.o:Hydrax.cpp:(.text+0x7c): first defined here
obj\Release\src\Hydrax\hydrax.o:Hydrax.cpp:(.text+0x17c): multiple definition of `Hydrax::Hydrax::setCausticsPower(float const&)'
obj\Release\src\Hydrax\Hydrax.o:Hydrax.cpp:(.text+0x17c): first defined here
obj\Release\src\Hydrax\hydrax.o:Hydrax.cpp:(.text+0x3b8): multiple definition of `Hydrax::Hydrax::setCausticsScale(float const&)'
obj\Release\src\Hydrax\Hydrax.o:Hydrax.cpp:(.text+0x3b8): first defined here
obj\Release\src\Hydrax\hydrax.o:Hydrax.cpp:(.text+0x4b4): multiple definition of `Hydrax::Hydrax::setSmoothPower(float const&)'
obj\Release\src\Hydrax\Hydrax.o:Hydrax.cpp:(.text+0x4b4): first defined here
obj\Release\src\Hydrax\hydrax.o:Hydrax.cpp:(.text+0x5b0): multiple definition of `Hydrax::Hydrax::setFoamTransparency(float const&)'
obj\Release\src\Hydrax\Hydrax.o:Hydrax.cpp:(.text+0x5b0): first defined here
obj\Release\src\Hydrax\hydrax.o:Hydrax.cpp:(.text+0x750): multiple definition of `Hydrax::Hydrax::setFoamStart(float const&)'
obj\Release\src\Hydrax\Hydrax.o:Hydrax.cpp:(.text+0x750): first defined here
obj\Release\src\Hydrax\hydrax.o:Hydrax.cpp:(.text+0x8f0): multiple definition of `Hydrax::Hydrax::setFoamScale(float const&)'
obj\Release\src\Hydrax\Hydrax.o:Hydrax.cpp:(.text+0x8f0): first defined here
obj\Release\src\Hydrax\hydrax.o:Hydrax.cpp:(.text+0xa90): multiple definition of `Hydrax::Hydrax::setFoamMaxDistance(float const&)'
obj\Release\src\Hydrax\Hydrax.o:Hydrax.cpp:(.text+0xa90): first defined here
obj\Release\src\Hydrax\hydrax.o:Hydrax.cpp:(.text+0xc30): multiple definition of `Hydrax::Hydrax::setSunArea(float const&)'
obj\Release\src\Hydrax\Hydrax.o:Hydrax.cpp:(.text+0xc30): first defined here
obj\Release\src\Hydrax\hydrax.o:Hydrax.cpp:(.text+0xdd0): multiple definition of `Hydrax::Hydrax::setSunStrength(float const&)'
obj\Release\src\Hydrax\Hydrax.o:Hydrax.cpp:(.text+0xdd0): first defined here
obj\Release\src\Hydrax\hydrax.o:Hydrax.cpp:(.text+0xf70): multiple definition of `Hydrax::Hydrax::_setStrength(float const&)'
obj\Release\src\Hydrax\Hydrax.o:Hydrax.cpp:(.text+0xf70): first defined here
obj\Release\src\Hydrax\hydrax.o:Hydrax.cpp:(.text+0x1118): multiple definition of `Hydrax::Hydrax::setSunColor(Ogre::Vector3 const&)'
obj\Release\src\Hydrax\Hydrax.o:Hydrax.cpp:(.text+0x1118): first defined here
obj\Release\src\Hydrax\hydrax.o:Hydrax.cpp:(.text+0x12d0): multiple definition of `Hydrax::Hydrax::setSunPosition(Ogre::Vector3 const&)'
obj\Release\src\Hydrax\Hydrax.o:Hydrax.cpp:(.text+0x12d0): first defined here
obj\Release\src\Hydrax\hydrax.o:Hydrax.cpp:(.text+0x14d4): multiple definition of `Hydrax::Hydrax::setPosition(Ogre::Vector3 const&)'
obj\Release\src\Hydrax\Hydrax.o:Hydrax.cpp:(.text+0x14d4): first defined here
obj\Release\src\Hydrax\hydrax.o:Hydrax.cpp:(.text+0x1674): multiple definition of `Hydrax::Hydrax::setShaderMode(Hydrax::MaterialManager::ShaderMode const&)'
obj\Release\src\Hydrax\Hydrax.o:Hydrax.cpp:(.text+0x1674): first defined here
obj\Release\src\Hydrax\hydrax.o:Hydrax.cpp:(.text+0x16e4): multiple definition of `Hydrax::Hydrax::setPolygonMode(Ogre::PolygonMode const&)'
obj\Release\src\Hydrax\Hydrax.o:Hydrax.cpp:(.text+0x16e4): first defined here
obj\Release\src\Hydrax\hydrax.o:Hydrax.cpp:(.text+0x1784): multiple definition of `Hydrax::Hydrax::DeviceListener::eventOccurred(std::string const&, std::map<std::string, std::string, std::less<std::string>, Ogre::STLAllocator<std::pair<std::string const, std::string>, Ogre::CategorisedAllocPolicy<(Ogre::MemoryCategory)0> > > const*)'
obj\Release\src\Hydrax\Hydrax.o:Hydrax.cpp:(.text+0x1784): first defined here
obj\Release\src\Hydrax\hydrax.o:Hydrax.cpp:(.text+0x17b4): multiple definition of `Hydrax::Hydrax::remove()'
obj\Release\src\Hydrax\Hydrax.o:Hydrax.cpp:(.text+0x17b4): first defined here
obj\Release\src\Hydrax\hydrax.o:Hydrax.cpp:(.text+0x1a08): multiple definition of `Hydrax::Hydrax::~Hydrax()'
obj\Release\src\Hydrax\Hydrax.o:Hydrax.cpp:(.text+0x1a08): first defined here
obj\Release\src\Hydrax\hydrax.o:Hydrax.cpp:(.text+0x1d30): multiple definition of `Hydrax::Hydrax::~Hydrax()'
obj\Release\src\Hydrax\Hydrax.o:Hydrax.cpp:(.text+0x1d30): first defined here
obj\Release\src\Hydrax\hydrax.o:Hydrax.cpp:(.text+0x2058): multiple definition of `Hydrax::Hydrax::Hydrax(Ogre::SceneManager*, Ogre::Camera*, Ogre::Viewport*)'
obj\Release\src\Hydrax\Hydrax.o:Hydrax.cpp:(.text+0x2058): first defined here
obj\Release\src\Hydrax\hydrax.o:Hydrax.cpp:(.text+0x25ac): multiple definition of `Hydrax::Hydrax::Hydrax(Ogre::SceneManager*, Ogre::Camera*, Ogre::Viewport*)'
obj\Release\src\Hydrax\Hydrax.o:Hydrax.cpp:(.text+0x25ac): first defined here
obj\Release\src\Hydrax\hydrax.o:Hydrax.cpp:(.text+0x2b00): multiple definition of `Hydrax::Hydrax::setNormalDistortion(float const&)'
obj\Release\src\Hydrax\Hydrax.o:Hydrax.cpp:(.text+0x2b00): first defined here
obj\Release\src\Hydrax\hydrax.o:Hydrax.cpp:(.text+0x2cf8): multiple definition of `Hydrax::Hydrax::setGlobalTransparency(float const&)'
obj\Release\src\Hydrax\Hydrax.o:Hydrax.cpp:(.text+0x2cf8): first defined here
obj\Release\src\Hydrax\hydrax.o:Hydrax.cpp:(.text+0x2ef0): multiple definition of `Hydrax::Hydrax::setFullReflectionDistance(float const&)'
obj\Release\src\Hydrax\Hydrax.o:Hydrax.cpp:(.text+0x2ef0): first defined here
obj\Release\src\Hydrax\hydrax.o:Hydrax.cpp:(.text+0x30e8): multiple definition of `Hydrax::Hydrax::_checkUnderwater(float const&)'
obj\Release\src\Hydrax\Hydrax.o:Hydrax.cpp:(.text+0x30e8): first defined here
obj\Release\src\Hydrax\hydrax.o:Hydrax.cpp:(.text+0x391c): multiple definition of `Hydrax::Hydrax::update(float const&)'
obj\Release\src\Hydrax\Hydrax.o:Hydrax.cpp:(.text+0x391c): first defined here
obj\Release\src\Hydrax\hydrax.o:Hydrax.cpp:(.text+0x3974): multiple definition of `Hydrax::Hydrax::_checkVisible()'
obj\Release\src\Hydrax\Hydrax.o:Hydrax.cpp:(.text+0x3974): first defined here
obj\Release\src\Hydrax\hydrax.o:Hydrax.cpp:(.text+0x3afc): multiple definition of `Hydrax::Hydrax::setVisible(bool const&)'
obj\Release\src\Hydrax\Hydrax.o:Hydrax.cpp:(.text+0x3afc): first defined here
obj\Release\src\Hydrax\hydrax.o:Hydrax.cpp:(.text+0x3b14): multiple definition of `Hydrax::Hydrax::setWaterColor(Ogre::Vector3 const&)'
obj\Release\src\Hydrax\Hydrax.o:Hydrax.cpp:(.text+0x3b14): first defined here
obj\Release\src\Hydrax\hydrax.o:Hydrax.cpp:(.text+0x4974): multiple definition of `Hydrax::Hydrax::setModule(Hydrax::Module::Module*, bool const&)'
obj\Release\src\Hydrax\Hydrax.o:Hydrax.cpp:(.text+0x4974): first defined here
obj\Release\src\Hydrax\hydrax.o:Hydrax.cpp:(.text+0x5894): multiple definition of `Hydrax::Hydrax::setDepthLimit(float const&)'
obj\Release\src\Hydrax\Hydrax.o:Hydrax.cpp:(.text+0x5894): first defined here
obj\Release\src\Hydrax\hydrax.o:Hydrax.cpp:(.text+0x5a14): multiple definition of `Hydrax::Hydrax::setComponents(Hydrax::HydraxComponent const&)'
obj\Release\src\Hydrax\Hydrax.o:Hydrax.cpp:(.text+0x5a14): first defined here
obj\Release\src\Hydrax\hydrax.o:Hydrax.cpp:(.text+0x75b0): multiple definition of `Hydrax::Hydrax::rotate(Ogre::Quaternion const&)'
obj\Release\src\Hydrax\Hydrax.o:Hydrax.cpp:(.text+0x75b0): first defined here
obj\Release\src\Hydrax\hydrax.o:Hydrax.cpp:(.text+0x77dc): multiple definition of `Hydrax::Hydrax::create()'
obj\Release\src\Hydrax\Hydrax.o:Hydrax.cpp:(.text+0x77dc): first defined here
collect2: ld returned 1 exit status
Process terminated with status 1 (0 minutes, 5 seconds)
0 errors, 7 warnings


As you can see it won't build the dll file.
To fix this right-click the Hadrax project and select Properties. Then select the "build targets" tab and unckeck the line in "Build target files" which says
"src\Hydray\hydrax.cpp". This is the line causing the error because the file has been added befor but with a capital "h".

After you do that the dll builds fine.

Linking dynamic library: bin\Release\Hydrax.dll
Creating library file: bin\Release\libHydrax.a
Output size is 1.10 MB


I hope this will help someone and be fixed in the next release.

edit: fixed a typo...

AndiNo

19-01-2011 15:17:53

Thanks for this info, it saved me a lot of headaches. :) I just hate these kind of compiler/linker problems... especially if they are caused by a bad project file :x

nevarim

20-01-2011 09:09:28

but with hydrax demo with ogre 1.7.x you have any problem?

p.s. for code i have compiled also hydrax and skyx for ogre 1.7.2 if you want


Nevarim

AndiNo

20-01-2011 10:59:51

The precompiled Hydrax demo didn't work for me because it crashes all the time. However I didn't try compiling and running the demo myself, I'm currently working on multiple things concurrently. I will give it a try within the next time.

nevarim

20-01-2011 11:18:57

for me all compiled right, but there are problem on hydrax material in media folder.....

in ogre.log you have same problem?

AndiNo

20-01-2011 18:26:14

I don't know what the problem was, but after a computer restart the precompiled Hydrax demo ran fine.
As I said I didn't try to compile and run the demo myself yet.