简体   繁体   中英

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? 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. The clang library requires vs 2010 to compile.

Any light you could shed on my problem is appreciated.

Thanks, 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. 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.

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. Here you will find good article on how to create a great library compatible with every compiler. http://chadaustin.me/cppinterface.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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