简体   繁体   English

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

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

Is there any way I can have the main functions for a library built in vs 2010 be accessible from a vs2005 project? 我可以通过vs2005项目访问vs 2010中内置库的主要功能吗? The problem that I face is that I have a project in vs 2005 that needs to use the clang frontend library to parse c code. 我面临的问题是我在vs 2005中有一个项目,需要使用clang前端库来解析c代码。 The clang library requires vs 2010 to compile. lang库需要vs 2010进行编译。

Any light you could shed on my problem is appreciated. 您对我的问题所能提出的任何见解均表示赞赏。

Thanks, Saketh 谢谢,Saketh

EDIT: 编辑:

I receive the following linker errors on compilation 我在编译时收到以下链接器错误

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

No. Within a single module, you cannot mix objects compiled against different major versions of the CRT. 不能。在一个模块中,您不能混合针对不同主要版本的CRT编译的对象。 This generally procludes mixing of objects compiled using different major versions of the compiler. 通常,这会导致混合使用不同主要版本的编译器编译的对象。

The correct thing to do would be to encapsulate your usage of Visual C++ 2010 within a DLL, and load that DLL from your executable compiled with Visual C++ 2005. Alternatively, upgrade your sources to use Visual C++ 2010. Visual C++ 2005 is ancient. 正确的做法是将您对Visual C ++ 2010的使用封装在一个DLL中,并从使用Visual C ++ 2005编译的可执行文件中加载该DLL。或者,升级您的源代码以使用Visual C ++2010。V​​isualC ++ 2005是古老的。

Your library functions should be at the lowest level here i mean that you should use C-style parameters to functions and use extern "C" to avoind compilers mangling. 您的库函数应处于最低级别,这意味着您应使用C样式参数来函数,并使用extern "C"避免编译器出错。 Here you will find good article on how to create a great library compatible with every compiler. 在这里,您将找到有关如何创建与每个编译器兼容的强大库的优秀文章。 http://chadaustin.me/cppinterface.html http://chadaustin.me/cppinterface.html

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

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