Reputation: 8376
I'm trying to link libprotobuf
to my project. In order to do that, I already compiled libprotobuf to a dynamic libray, which is on my library path.
However, when compiling with /MD
, I get the following error from the linker:
3>libprotobuf.lib(int128.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MD_DynamicRelease' in component.obj [C:\Projekte\P3D-ECS\p3d_e
So, I changed the flag from /MD
to /MT
, and those disappeared. However, now the linker is failing to link the standard library, and cannot find symbols like std::basic_ostream
, with a lot of errors like this:
error LNK2001: unresolved external symbol "__declspec(dllimport) public: __int64 __cdecl std::basic_streambuf<char,struct std::char_traits<char> >::sputn(char const *,__int64)" (__imp_?sputn@?$basic_streambuf@DU?$char_traits@D@std@@@std@@QEAA_JPEBD_J@Z)
I have already tried adding libcmt
and MSVCRT
to my linker dependencies, without success.
It seems that my DLL simply fails to compile with the /MT
flag, regardless of linking libprotobuf
or not. What am I missing?
Upvotes: 1
Views: 322
Reputation: 8376
After reading through the protobuf CMakeLists, I found the following solution:
-Dprotobuf_MSVC_STATIC_RUNTIME=OFF
Had to be passed to the cmake command, to make protobuf use /MD
instead of /MT
.
Upvotes: 1