1

有什么方法可以从 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(_int64)" (_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 *,_int64)" (_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 " (_imp?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

4

2 回答 2

2

不可以。在单个模块中,您不能混合针对 CRT 的不同主要版本编译的对象。这通常会导致混合使用不同主要版本的编译器编译的对象。

正确的做法是将您对 Visual C++ 2010 的使用封装在一个 DLL 中,并从使用 Visual C++ 2005 编译的可执行文件加载该 DLL。或者,升级您的源代码以使用 Visual C++ 2010。V​​isual C++ 2005 是古老的。

于 2013-07-29T19:58:54.890 回答
0

您的库函数应该处于最低级别,我的意思是您应该对函数使用 C 风格的参数并使用它extern "C"来避免编译器错误。在这里,您将找到有关如何创建与每个编译器兼容的出色库的好文章。http://chadaustin.me/cppinterface.html

于 2013-07-29T20:15:37.083 回答