简体   繁体   中英

Mixing static and dynamic (shared) libraries?

I am working with three different libraries, a Core (can be compiled as static or DLL), Graphics (can be compiled as static or DLL - Dealing with Ogre), Physics (can be compiled as static only due to licensing - Havok). A project then uses a combination of the libraries depending on the needs. The Physics portion is dependent on some functions of the Graphics and Core while the Graphics is dependent on some functionality of the Core . The project works fine with all the libraries statically linked in debug and release. I get the following error when using dynamically linked libraries of the Core and Graphics but a statically linked Physics library.

Error 1 error LNK2005: "public: unsigned int __thiscall OgreFW::FwErrorLog::GetError(void)" (?GetError@FwErrorLog@OgreFW@@QAEIXZ) already defined in FwCore_d_dll.lib(FwCore_d.dll) FwHavok_d.lib

I can see what the error means, but I am confused on how to circumvent this. If my libraries are dependant on each other like this, and the licensing of the physics engine (Havok) only allows static linking, do I need to rethink my design (which is a big problem :( ) or is there a way around it?

Thanks

EDIT: I have already checked to make sure all the libraries are being compiled with MDd

EDIT2: I can use /FORCE:MULTIPLE but that is hiding the problem rather than solving it

EDIT3: Apologies for several edits. The function GetError() is defined in the header, if I place it in the source file, the linking error goes away. Why is that?

"The project works fine with all the libraries statically linked in debug and release."

Isn't that your answer then? What advantage would dynamic linking have for this scenario?

I found a solution but I don't know why it works. There would be an explanation if all the functions (instead of just the one) that were defined in the header gave the linking error, but no, there are only two.

Anyway, the solution is to put the definitions of the functions in the source files. Why does that work? If anybody has an explanation to that, that will be great.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM