Jump to content
  • 0

[Probably Solved][Question] Linking errors on new file


Guest LilleCarl_

Question

Hello guys! I am trying to create a new file called Custom.cpp which should contain all custom functions i create. For easier git merging with upstream etc...

But when i declare a function in Player.h and then define it in Custom.cpp with Player::Function() i get LOADS of linker errors, just like this one:

3>game.lib(Player.obj) : error LNK2005: "public: void __thiscall PlayerTaxi::InitTaxiNodesForLevel(unsigned int,unsigned int)" ([email protected]@@[email protected]) already defined in mangosd.lib(mangosd.exe)

3>shared.lib(BigNumber.obj) : error LNK2001: unresolved external symbol _BN_add

I do not know anything about linker errors, and even if i google they just say i do not link properly, which says nothing to me.

Could someone give me a hint on what to do here? =)

SOLUTION:

I declared my function as virtual in Player.h

Regards

Link to comment
Share on other sites

4 answers to this question

Recommended Posts

But when i declare a function in Player.h and then define it in Custom.cpp with Player::Function() i get LOADS of linker errors, just like this one:
3>game.lib(Player.obj) : error LNK2005: "public: void __thiscall PlayerTaxi::InitTaxiNodesForLevel(unsigned int,unsigned int)" ([email protected]@@[email protected]) already defined in mangosd.lib(mangosd.exe)

The real problem is that you have functions defined in multiple static libraries: some function is apparently defined in both game.lib and mangosd.lib. So the linker isn't sure which one to choose, and gives an error.

It looks like your Custom.cpp is compiled in both libs. Don't do that and you should be fine :)

Link to comment
Share on other sites

But when i declare a function in Player.h and then define it in Custom.cpp with Player::Function() i get LOADS of linker errors, just like this one:
3>game.lib(Player.obj) : error LNK2005: "public: void __thiscall PlayerTaxi::InitTaxiNodesForLevel(unsigned int,unsigned int)" ([email protected]@@[email protected]) already defined in mangosd.lib(mangosd.exe)

The real problem is that you have functions defined in multiple static libraries: some function is apparently defined in both game.lib and mangosd.lib. So the linker isn't sure which one to choose, and gives an error.

It looks like your Custom.cpp is compiled in both libs. Don't do that and you should be fine :)

I only added custom.cpp to the game project tho... But since mangosd.lib includes game.lib that might be what causes it?

Edit: This function PlayerTaxi::InitTaxiNodesForLevel is completely unmodified and i did not "redefine" it anywhere in custom.cpp so it must be the compiler looking at something i do not do ^^,

Thanks for the reply! =)

Link to comment
Share on other sites

No, mangosd.lib does not 'include' game.lib. They are both static libraries, and one might need the code in the other to work eventually as part of an executable, but that's about it. Look at a static library as 'a container with some object files (compiled code)'; they are nothing more and nothing less. In particular, they have no notion of dependencies between them. Eventually mangosd.exe does need them both to link though :)

Yet somehow, they both have the same function defined. If your custom.cpp was only added to the game project, that should be fine. Interestingly, the InitTaxiNodesForLevel mentioned here has a single definition in my source tree: it's the one with the two integers as parameter (race and level apparently), which is only defined in Player.cpp. That one should be in the project for game.lib. So it looks like that function somehow made it in the mangosd project too... either by compiling Player.cpp in that project too (but I can't imagine you added it to a second project) or by some other means (including code or copy/pasting code).

In theory, you can figure out what's wrong given the mangosd.lib file. There is a utility installed with Visual Studio called "dumpbin". With this tool you could check what's inside the library. The option /ARCHIVEMEMBERS comes to mind to check whether Player.o is in it or not, or even /SYMBOLS to check what object file (and hence which source file) was responsible for pulling the function definition in the library. But perhaps that's slightly overkill to diagnose the problem :P

Link to comment
Share on other sites

Im sorry, i guesss you didnt get enough info, there are over 400 linker errors. But there are only 2001 and 2005. So i just thought i could just include one of each (as they all are the same).

Custom.cpp was indeed only added to the game project. Added scriptdev2 to mangos solution, but that is not what is causing the error. I think this is strange, i will try and see what i can do with dumpbin!

Thank you for all your response! Hope i can get a solution on this (even if it works just fine with the virtual is guess there must be some drawback) :)

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. Privacy Policy Terms of Use