c++ - 在使用 vs2005 的项目中包含一个在 vs2010 中编译的 .lib 文件

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

有什么方法可以让 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(_<em>int64)" (</em>_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 *,_<em>int64)" (</em>_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 " (_<em>imp</em>?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​​isual C++ 2005 是古老。

关于c++ - 在使用 vs2005 的项目中包含一个在 vs2010 中编译的 .lib 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17932853/

相关文章:

c++ - 构造函数特化要求

c++ - System.Windows.Controls.Expander MFC 等价物

c++ - 部署简单的 C++ 应用程序

C++ - 向事件进程发出动态命令

c++ - __attribute__((format(printf, 1, 2))) 用于 MSVC?

c++ - 计数倒置 C++

c++ - g++ (mingw) 表示 to_string 不是 std 的成员

c++ - 为什么范围解析在这里不起作用?

visual-studio-2010 - 依赖 Walker 错误 : The Side-by-Side configuration information for "ABC.DLL" contains errors

visual-studio-2010 - CUDA 5 和 Visual Studio 2010 智能感知错误