有什么方法可以让 vs2005 项目访问内置于 vs 2010 的库的主要功能?我面临的问题是我在 vs 2005 中有一个项目需要使用 clang 前端库来解析 c 代码。 clang 库需要 vs 2010 编译。
如果您对我的问题有所了解,我们将不胜感激。
谢谢, 萨克斯
编辑:
我在编译时收到以下链接器错误
1>hello.lib(hello.obj) : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __int64 __thiscall std::ios_base::width(_<em>int64)" (</em>_imp_?width@ios_base@std@@QAE_J_J@Z) referenced in function "class std::basic_ostream > & __cdecl std::operator<< >(class std::basic_ostream > &,char const *)" (??$?6U?$char_traits@D@std@@@std@@YAAAV?$basic_ostream@DU?$char_traits@D@std@@@0@AAV10@PBD@Z)
1>hello.lib(hello.obj) : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __int64 __thiscall std::basic_streambuf >::sputn(char const *,_<em>int64)" (</em>_imp_?sputn@?$basic_streambuf@DU?$char_traits@D@std@@@std@@QAE_JPBD_J@Z) referenced in function "class std::basic_ostream > & __cdecl std::operator<< >(class std::basic_ostream > &,char const *)" (??$?6U?$char_traits@D@std@@@std@@YAAAV?$basic_ostream@DU?$char_traits@D@std@@@0@AAV10@PBD@Z)
1>hello.lib(hello.obj) : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __int64 __thiscall std::ios_base::width(void)const " (_<em>imp</em>?width@ios_base@std@@QBE_JXZ) referenced in function "class std::basic_ostream > & __cdecl std::operator<< >(class std::basic_ostream > &,char const *)" (??$?6U?$char_traits@D@std@@@std@@YAAAV?$basic_ostream@DU?$char_traits@D@std@@@0@AAV10@PBD@Z)
1>C:\Users\sakethk\Perforce\sakethk_SAKETHK_7702\source\qcom\qct\modem\uim\tools\sakethk\hello05\Debug\hello05.exe : fatal error LNK1120: 3 unresolved externals
最佳答案
没有。在单个模块中,您不能混合针对不同主要版本的 CRT 编译的对象。这通常会导致混合使用不同主要版本的编译器编译的对象。
正确的做法是将您对 Visual C++ 2010 的使用封装在一个 DLL 中,并从使用 Visual C++ 2005 编译的可执行文件中加载该 DLL。或者,升级您的源代码以使用 Visual C++ 2010。Visual C++ 2005 是古老。
关于c++ - 在使用 vs2005 的项目中包含一个在 vs2010 中编译的 .lib 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17932853/