包括在vs2010中使用vs2005的项目中编译的.lib文件

时间:2013-07-29 19:45:16

标签: c++ visual-studio-2010 visual-c++ visual-studio-2005

有什么方法可以从vs2005项目中访问vs 2010中构建的库的主要功能?我面临的问题是我在vs 2005中有一个项目需要使用clang前端库来解析c代码。 clang库需要vs 2010进行编译。

您可以解决我的问题所带来的任何亮点。

谢谢, Saketh

编辑:

我在编译时收到以下链接器错误

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

2 个答案:

答案 0 :(得分:2)

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

正确的做法是将您在Visual C ++ 2010中的使用封装在DLL中,并从使用Visual C ++ 2005编译的可执行文件中加载该DLL。或者,升级您的源以使用Visual C ++ 2010. Visual C ++ 2005 is古

答案 1 :(得分:0)

你的库函数应该处于最低级别,这意味着你应该使用C风格的参数来运行函数,并使用extern "C"来避免编译器损坏。在这里,您将找到关于如何创建与每个编译器兼容的优秀库的好文章。 http://chadaustin.me/cppinterface.html

相关问题