无法与标准库链接

时间:2016-11-08 19:13:22

标签: c++ visual-studio-2015 linker protocol-buffers

我试图将libprotobuf链接到我的项目。为了做到这一点,我已经将libprotobuf编译为动态库,它位于我的库路径上。

但是,在使用/MD进行编译时,我从链接器中收到以下错误:

 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

所以,我将旗帜从/MD更改为/MT,然后消失了。但是,现在链接器无法链接标准库,并且找不到像std::basic_ostream这样的符号,有很多错误,如下所示:

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)

我已经尝试将libcmtMSVCRT添加到我的链接器依赖项中,但没有成功。

似乎我的DLL无法使用/MT标志进行编译,无论是否链接libprotobuf我缺少什么?

1 个答案:

答案 0 :(得分:1)

在阅读了protobuf CMakeLists后,我找到了以下解决方案:

-Dprotobuf_MSVC_STATIC_RUNTIME=OFF

不得不传递给cmake命令,使protobuf使用/MD代替/MT

相关问题