Jump to content
  • Advertisement
Sign in to follow this  
cstdio

Dynamic lib using a static lib (VC++ .NET)

This topic is 4831 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all. I'm trying to use a static lib (a game engine) within a dynamic lib (a DirectShow filter) and I'm getting a wealth of LNK2005 errors. I've never run into this problem before without being able to fix it. Usually it's a simple matter of making sure that both libs are multi-threaded or forcing the linker to ignore a few libs, but so far I haven't been able to get anything to work. The static lib is multi-threaded and the dynamic lib is multi-threaded dll. I'd appreciate any help/wisdom you can offer. Worse case, I'll hack the engine into a dll and give that a shot...but I'd like to avoid that unless absolutely necessary. VS gives me this garbage output: Linking... msvcprt.lib(MSVCP71.dll) : error LNK2005: "public: __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::~basic_string<char,struct std::char_traits<char>,class std::allocator<char> >(void)" (??1?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@XZ) already defined in GraphicsEngine.lib(Engine.obj) [SNIP: more msvcptr.lib LNK2005 errors] msvcprt.lib(MSVCP71.dll) : error LNK2005: "public: bool __thiscall std::ios_base::good(void)const " (?good@ios_base@std@@QBE_NXZ) already defined in GraphicsEngine.lib(Logger.obj) msvcprt.lib(MSVCP71.dll) : error LNK2005: "public: void __thiscall std::basic_ostream<char,struct std::char_traits<char> >::_Osfx(void)" (?_Osfx@?$basic_ostream@DU?$char_traits@D@std@@@std@@QAEXXZ) already defined in GraphicsEngine.lib(Logger.obj) libcmt.lib(stdexcpt.obj) : error LNK2005: "public: __thiscall exception::exception(class exception const &)" (??0exception@@QAE@ABV0@@Z) already defined in msvcrt.lib(MSVCR71.dll) libcmt.lib(stdexcpt.obj) : error LNK2005: "public: __thiscall bad_cast::bad_cast(char const *)" (??0bad_cast@@QAE@PBD@Z) already defined in msvcrt.lib(MSVCR71.dll) libcmt.lib(stdexcpt.obj) : error LNK2005: "public: __thiscall bad_cast::bad_cast(class bad_cast const &)" (??0bad_cast@@QAE@ABV0@@Z) already defined in msvcrt.lib(MSVCR71.dll) [SNIP: more libcpmt.lib LNK2005 errors] libcpmt.lib(xlock.obj) : error LNK2005: "public: __thiscall std::_Lockit::~_Lockit(void)" (??1_Lockit@std@@QAE@XZ) already defined in msvcprt.lib(MSVCP71.dll) msvcprt.lib(MSVCP71.dll) : warning LNK4006: "public: __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::~basic_string<char,struct std::char_traits<char>,class std::allocator<char> >(void)" (??1?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@XZ) already defined in GraphicsEngine.lib(Engine.obj); second definition ignored [SNIP: more "ignoring redefinition" warnings] Creating library .\Release/PushSource.lib and object .\Release/PushSource.exp libcmt.lib(crt0.obj) : error LNK2019: unresolved external symbol _main referenced in function _mainCRTStartup Release/PushSourceOpenGL.dll : fatal error LNK1120: 1 unresolved externals Build log was saved at "xxx\BuildLog.htm" PushSourceOpenGL - 63 error(s), 61 warning(s) ---------------------- Done ---------------------- Build: 2 succeeded, 1 failed, 0 skipped

Share this post


Link to post
Share on other sites
Advertisement
It looks like the problem is that your static lib already contains implementations of the standard C++ classes (like std::string) compiled into it, while those same classes are defined inside msvcprt. You would have to either change your static library to use Multithreaded DLL or change your DLL to using Multithreaded. Note that static libraries can still use Multithreaded DLL and DLLs can still use Multithreaded.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!