繁体   English   中英

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

[英]including a .lib file compiled in vs2010 in a project that is using vs2005

我可以通过vs2005项目访问vs 2010中内置库的主要功能吗? 我面临的问题是我在vs 2005中有一个项目,需要使用clang前端库来解析c代码。 lang库需要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

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

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

您的库函数应处于最低级别,这意味着您应使用C样式参数来函数,并使用extern "C"避免编译器出错。 在这里,您将找到有关如何创建与每个编译器兼容的强大库的优秀文章。 http://chadaustin.me/cppinterface.html

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM