在VS2012应用程序中使用VS2005构建的库的链接器错误

时间:2016-08-09 15:22:49

标签: c++ visual-studio visual-studio-2012 visual-studio-2005 linker-errors

我正在尝试在VS2005中构建一个库。它是使用VS2012开发的,在VS2012中一切正常,遗憾的是,我们需要为库提供VS2005项目(我使用CMake生成两个项目)。我能够使用VS2005构建它,但是当我尝试链接它时,我得到多个链接器错误(主要是LNK2001和LNK2019)。

当我生成VS2005库并将其链接到VS2012测试应用程序(都定义Runtime MDd)进行调试时,我收到以下错误:

Error   26  error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __thiscall std::_Container_base::_Orphan_all(void)const " (__imp_?_Orphan_all@_Container_base@std@@QBEXXZ) referenced in function "protected: void __thiscall std::vector<class Class1 *,class std::allocator<class Class1 *> >::_Tidy(void)" (?_Tidy@?$vector@PAVClass1@@V?$allocator@PAVClass1@@@std@@@std@@IAEXXZ) C:\Users\XXXXX\Documents\Visual Studio 2012\Projects\Test-Name\Test-Name\testLibraryd.lib(Class2.obj)   Test-Name
Error   20  error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (__imp_??0?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@ABV01@@Z) referenced in function "public: __thiscall std::logic_error::logic_error(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (??0logic_error@std@@QAE@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@1@@Z) C:\Users\XXXXX\Documents\Visual Studio 2012\Projects\Test-Name\Test-Name\testLibraryd.lib(Class3.obj)   Test-Name
Error   17  error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall std::_Container_base::~_Container_base(void)" (__imp_??1_Container_base@std@@QAE@XZ) referenced in function "public: __thiscall std::_Tmap_traits<unsigned short,class Class5 *,struct std::less<unsigned short>,class std::allocator<struct std::pair<unsigned short const ,class Class5 *> >,0>::~_Tmap_traits<unsigned short,class Class5 *,struct std::less<unsigned short>,class std::allocator<struct std::pair<unsigned short const ,class Class5 *> >,0>(void)" (??1?$_Tmap_traits@GPAVClass5@@U?$less@G@std@@V?$allocator@U?$pair@$$CBGPAVClass5@@@std@@@3@$0A@@std@@QAE@XZ)   C:\Users\XXXXX\Documents\Visual Studio 2012\Projects\Test-Name\Test-Name\testLibraryd.lib(Class3.obj)   Test-Name
Error   23  error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall std::_Container_base::_Container_base(void)" (__imp_??0_Container_base@std@@QAE@XZ) referenced in function "public: __thiscall std::_Tmap_traits<unsigned short,class Class5 *,struct std::less<unsigned short>,class std::allocator<struct std::pair<unsigned short const ,class Class5 *> >,0>::_Tmap_traits<unsigned short,class Class5 *,struct std::less<unsigned short>,class std::allocator<struct std::pair<unsigned short const ,class Class5 *> >,0>(struct std::less<unsigned short>)" (??0?$_Tmap_traits@GPAVClass5@@U?$less@G@std@@V?$allocator@U?$pair@$$CBGPAVClass5@@@std@@@3@$0A@@std@@QAE@U?$less@G@1@@Z) C:\Users\XXXXX\Documents\Visual Studio 2012\Projects\Test-Name\Test-Name\testLibraryd.lib(Class3.obj)   Test-Name
Error   21  error LNK2001: unresolved external symbol "__declspec(dllimport) public: __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (__imp_??0?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@ABV01@@Z)  C:\Users\XXXXX\Documents\Visual Studio 2012\Projects\Test-Name\Test-Name\testLibraryd.lib(Class2.obj)   Test-Name
Error   22  error LNK2001: unresolved external symbol "__declspec(dllimport) public: __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (__imp_??0?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@ABV01@@Z)  C:\Users\XXXXX\Documents\Visual Studio 2012\Projects\Test-Name\Test-Name\testLibraryd.lib(Class4.obj)   Test-Name
Error   18  error LNK2001: unresolved external symbol "__declspec(dllimport) public: __thiscall std::_Container_base::~_Container_base(void)" (__imp_??1_Container_base@std@@QAE@XZ)    C:\Users\XXXXX\Documents\Visual Studio 2012\Projects\Test-Name\Test-Name\testLibraryd.lib(Class2.obj)   Test-Name
Error   19  error LNK2001: unresolved external symbol "__declspec(dllimport) public: __thiscall std::_Container_base::~_Container_base(void)" (__imp_??1_Container_base@std@@QAE@XZ)    C:\Users\XXXXX\Documents\Visual Studio 2012\Projects\Test-Name\Test-Name\testLibraryd.lib(Class4.obj)   Test-Name
Error   24  error LNK2001: unresolved external symbol "__declspec(dllimport) public: __thiscall std::_Container_base::_Container_base(void)" (__imp_??0_Container_base@std@@QAE@XZ) C:\Users\XXXXX\Documents\Visual Studio 2012\Projects\Test-Name\Test-Name\testLibraryd.lib(Class2.obj)   Test-Name
Error   25  error LNK2001: unresolved external symbol "__declspec(dllimport) public: __thiscall std::_Container_base::_Container_base(void)" (__imp_??0_Container_base@std@@QAE@XZ) C:\Users\XXXXX\Documents\Visual Studio 2012\Projects\Test-Name\Test-Name\testLibraryd.lib(Class4.obj)   Test-Name

当我生成VS2005库并将其链接到VS2012测试应用程序(都定义Runtime MD)以供发布时,我会收到以下错误:

Error   6   error LNK2001: unresolved external symbol "__declspec(dllimport) public: __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (__imp_??0?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@ABV01@@Z)  C:\Users\XXXXX\Documents\Visual Studio 2012\Projects\Test-Name\Test-Name\testLibrary.lib(Class3.obj)    Test-Name
Error   7   error LNK2001: unresolved external symbol "__declspec(dllimport) public: __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (__imp_??0?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@ABV01@@Z)  C:\Users\XXXXX\Documents\Visual Studio 2012\Projects\Test-Name\Test-Name\testLibrary.lib(Class2.obj)    Test-Name
Error   8   error LNK2001: unresolved external symbol "__declspec(dllimport) public: __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (__imp_??0?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@ABV01@@Z)  C:\Users\XXXXX\Documents\Visual Studio 2012\Projects\Test-Name\Test-Name\testLibrary.lib(Class4.obj)    Test-Name

为了记录,我已经就这些问题咨询了谷歌,遇到了一些可能的原因:

  1. 缺少一些类定义 - 事实并非如此,因为当我在VS2005中创建的测试应用程序中测试VS2005中构建的库时,我能够使用它并进行调试而不会出现问题。

  2. 使用字符串 - 我的项目中根本不使用字符串,甚至没有定义字符串标题。我最多只使用地图。

  3. 使用与测试应用程序https://social.msdn.microsoft.com/Forums/vstudio/en-US/8042a534-aa8b-4f99-81ee-e5ff39ae6e69/lnk2001-lnk2019-link-static-libraries-build-with-vs2005-with-vs2008?forum=vcgeneral相同的编译器解决构建问题 - 不幸的是,我们的要求是必须使用VS2005。

  4. 使用MT和MTd - 我们的另一个要求是,我们需要在所有运行时提供库,甚至使用MT和MTd导致链接器错误。

  5. 忽略应用程序属性中的默认库 - 我不会忽略默认库。

  6. 我非常感谢您就此问题提供的任何反馈。我觉得非常奇怪的是,当我不使用任何字符串时,大多数错误都是关于字符串的。

0 个答案:

没有答案
相关问题