我在 Microsoft visual studio professionnal 2010 下有一个 c++ qt5 项目。我必须在我的项目中包含一个库 .lib,它是用 Microsoft Visual 2005 编译的,并且依赖于 STL 的 visual 2005 版本。结果,当我尝试编译我的项目时,出现了以下链接错误(这里是前三个错误):
libmegamatching.lib(BImage.obj) : error LNK2001: unresolved external symbol "__declspec(dllimport) public: int __thiscall std::basic_streambuf<char,struct std::char_traits<char> >::sputn(char const *,int)" (__imp_?sputn@?$basic_streambuf@DU?$char_traits@D@std@@@std@@QAEHPBDH@Z)
libmegamatching.lib(makeCanonicalImage.obj) : error LNK2001: unresolved external symbol "__declspec(dllimport) public: int __thiscall std::basic_streambuf<char,struct std::char_traits<char> >::sputn(char const *,int)" (__imp_?sputn@?$basic_streambuf@DU?$char_traits@D@std@@@std@@QAEHPBDH@Z)
M_Control.lib(Logger.obj) : error LNK2001: unresolved external symbol "__declspec(dllimport) public: int __thiscall std::basic_streambuf<char,struct std::char_traits<char> >::sputn(char const *,int)" (__imp_?sputn@?$basic_streambuf@DU?$char_traits@D@std@@@std@@QAEHPBDH@Z)
我的同事通过将库封装到 Microsoft 管理的 C++ 库中解决了这个问题……但我还没有尝试这样做,因为我对将 .NET 依赖项添加到我的项目并不感兴趣。 还有其他解决方案吗?当然,我不能用 visual 2010 重新编译库,也不能更改我的 visual 版本。
我正在考虑制作一个视觉 2005 std 库 .lib...但我不知道是否有办法做到这一点?
提前致谢
最佳答案
您需要 [a] 使用 Visual C++ 2010 重新编译库,或者 [b] 将库封装在它自己的模块 (DLL) 中并在其上提供平面 C 接口(interface)。
在单个模块中,不能混合使用不同主要版本的 Visual C++ 库构建的对象。
关于c++ - 在 Visual C 2010 项目中包含一个 Visual 2005 库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17506707/