从VS2012项目链接使用VS2008构建的静态库?它们兼容吗?

时间:2012-08-22 13:38:22

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

我有一堆静态.lib文件,包括mysqlclient.lib,v8_base.lib和mysqlpp.lib,我链接到我的项目,这些都是使用Visual Studio 2008构建的,它们是使用/ MT运行时库选项构建的

我刚刚尝试升级到VS2012并且代码编译得很好但是当项目被链接时我得到以下错误(总共超过500个错误):

Error   47  error LNK2019: unresolved external symbol "public: __thiscall std::_Mutex::~_Mutex(void)" (??1_Mutex@std@@QAE@XZ) referenced in function "public: void __thiscall std::ios_base::clear(int,bool)" (?clear@ios_base@std@@QAEXH_N@Z)  D:\server\mysqlpp.lib(dbdriver.obj) server
Error   48  error LNK2001: unresolved external symbol "public: __thiscall std::_Mutex::~_Mutex(void)" (??1_Mutex@std@@QAE@XZ)   D:\server\mysqlpp.lib(datetime.obj) server
Error   49  error LNK2001: unresolved external symbol "public: __thiscall std::_Mutex::~_Mutex(void)" (??1_Mutex@std@@QAE@XZ)   D:\server\mysqlpp.lib(stadapter.obj)    server
Error   50  error LNK2001: unresolved external symbol "public: __thiscall std::_Mutex::~_Mutex(void)" (??1_Mutex@std@@QAE@XZ)   D:\server\mysqlpp.lib(sqlstream.obj)    server
Error   51  error LNK2001: unresolved external symbol "public: __thiscall std::_Mutex::~_Mutex(void)" (??1_Mutex@std@@QAE@XZ)   D:\server\mysqlpp.lib(connection.obj)   server
Error   52  error LNK2001: unresolved external symbol "public: __thiscall std::_Mutex::~_Mutex(void)" (??1_Mutex@std@@QAE@XZ)   D:\server\mysqlpp.lib(mystring.obj) server
Error   53  error LNK2001: unresolved external symbol "public: __thiscall std::_Mutex::~_Mutex(void)" (??1_Mutex@std@@QAE@XZ)   D:\server\mysqlpp.lib(row.obj)  server
Error   54  error LNK2001: unresolved external symbol "public: __thiscall std::_Mutex::~_Mutex(void)" (??1_Mutex@std@@QAE@XZ)   D:\server\mysqlpp.lib(query.obj)    server
Error   55  error LNK2001: unresolved external symbol "long const std::_BADOFF" (?_BADOFF@std@@3JB) D:\server\mysqlpp.lib(dbdriver.obj) server
Error   56  error LNK2001: unresolved external symbol "long const std::_BADOFF" (?_BADOFF@std@@3JB) D:\server\mysqlpp.lib(datetime.obj) server
Error   57  error LNK2001: unresolved external symbol "long const std::_BADOFF" (?_BADOFF@std@@3JB) D:\server\mysqlpp.lib(stadapter.obj)    server
Error   58  error LNK2001: unresolved external symbol "long const std::_BADOFF" (?_BADOFF@std@@3JB) D:\server\mysqlpp.lib(sqlstream.obj)    server
Error   59  error LNK2001: unresolved external symbol "long const std::_BADOFF" (?_BADOFF@std@@3JB) D:\server\mysqlpp.lib(connection.obj)   server
Error   60  error LNK2001: unresolved external symbol "long const std::_BADOFF" (?_BADOFF@std@@3JB) D:\server\mysqlpp.lib(mystring.obj) server
Error   61  error LNK2001: unresolved external symbol "long const std::_BADOFF" (?_BADOFF@std@@3JB) D:\server\mysqlpp.lib(row.obj)  server
Error   62  error LNK2001: unresolved external symbol "long const std::_BADOFF" (?_BADOFF@std@@3JB) D:\server\mysqlpp.lib(query.obj)    server
Error   63  error LNK2001: unresolved external symbol "public: static void __cdecl std::_String_base::_Xran(void)" (?_Xran@_String_base@std@@SAXXZ) D:\server\mysqlpp.lib(qparms.obj)   server
Error   64  error LNK2001: unresolved external symbol "public: static void __cdecl std::_String_base::_Xran(void)" (?_Xran@_String_base@std@@SAXXZ) D:\server\mysqlpp.lib(sqlstream.obj)    server
Error   65  error LNK2001: unresolved external symbol "public: static void __cdecl std::_String_base::_Xran(void)" (?_Xran@_String_base@std@@SAXXZ) D:\server\mysqlpp.lib(options.obj)  server
Error   66  error LNK2001: unresolved external symbol "public: static void __cdecl std::_String_base::_Xran(void)" (?_Xran@_String_base@std@@SAXXZ) D:\server\mysqlpp.lib(field_types.obj)  server
Error   67  error LNK2019: unresolved external symbol "public: static void __cdecl std::_String_base::_Xran(void)" (?_Xran@_String_base@std@@SAXXZ) referenced in function "public: char __thiscall mysqlpp::SQLTypeAdapter::at(unsigned int)const " (?at@SQLTypeAdapter@mysqlpp@@QBEDI@Z)  D:\server\mysqlpp.lib(stadapter.obj)    server
Error   68  error LNK2001: unresolved external symbol "public: static void __cdecl std::_String_base::_Xran(void)" (?_Xran@_String_base@std@@SAXXZ) D:\server\mysqlpp.lib(manip.obj)    server
Error   69  error LNK2001: unresolved external symbol "public: static void __cdecl std::_String_base::_Xran(void)" (?_Xran@_String_base@std@@SAXXZ) D:\server\mysqlpp.lib(null.obj) server
Error   70  error LNK2001: unresolved external symbol "public: static void __cdecl std::_String_base::_Xran(void)" (?_Xran@_String_base@std@@SAXXZ) D:\server\mysqlpp.lib(datetime.obj) server
Error   71  error LNK2001: unresolved external symbol "public: static void __cdecl std::_String_base::_Xran(void)" (?_Xran@_String_base@std@@SAXXZ) D:\server\mysqlpp.lib(type_info.obj)    server
Error   72  error LNK2001: unresolved external symbol "public: static void __cdecl std::_String_base::_Xran(void)" (?_Xran@_String_base@std@@SAXXZ) D:\server\mysqlpp.lib(vallist.obj)  server
Error   73  error LNK2001: unresolved external symbol "public: static void __cdecl std::_String_base::_Xran(void)" (?_Xran@_String_base@std@@SAXXZ) D:\server\mysqlpp.lib(field_names.obj)  server
Error   74  error LNK2001: unresolved external symbol "public: static void __cdecl std::_String_base::_Xran(void)" (?_Xran@_String_base@std@@SAXXZ) D:\server\mysqlpp.lib(query.obj)    server
Error   75  error LNK2001: unresolved external symbol "public: static void __cdecl std::_String_base::_Xran(void)" (?_Xran@_String_base@std@@SAXXZ) D:\server\mysqlpp.lib(dbdriver.obj) server
Error   76  error LNK2001: unresolved external symbol "public: static void __cdecl std::_String_base::_Xran(void)" (?_Xran@_String_base@std@@SAXXZ) D:\server\mysqlpp.lib(tcp_connection.obj)   server
Error   77  error LNK2001: unresolved external symbol "public: static void __cdecl std::_String_base::_Xran(void)" (?_Xran@_String_base@std@@SAXXZ) D:\server\mysqlpp.lib(uds_connection.obj)   server
Error   78  error LNK2001: unresolved external symbol "public: static void __cdecl std::_String_base::_Xran(void)" (?_Xran@_String_base@std@@SAXXZ) D:\server\mysqlpp.lib(connection.obj)   server
Error   79  error LNK2001: unresolved external symbol "public: static void __cdecl std::_String_base::_Xran(void)" (?_Xran@_String_base@std@@SAXXZ) D:\server\mysqlpp.lib(mystring.obj) server
Error   80  error LNK2001: unresolved external symbol "public: static void __cdecl std::_String_base::_Xran(void)" (?_Xran@_String_base@std@@SAXXZ) D:\server\mysqlpp.lib(row.obj)  server
Error   81  error LNK2001: unresolved external symbol "public: static void __cdecl std::_String_base::_Xran(void)" (?_Xran@_String_base@std@@SAXXZ) D:\server\mysqlpp.lib(result.obj)   server
Error   82  error LNK2001: unresolved external symbol "public: static void __cdecl std::_String_base::_Xlen(void)" (?_Xlen@_String_base@std@@SAXXZ) D:\server\mysqlpp.lib(null.obj) server
Error   83  error LNK2001: unresolved external symbol "public: static void __cdecl std::_String_base::_Xlen(void)" (?_Xlen@_String_base@std@@SAXXZ) D:\server\mysqlpp.lib(qparms.obj)   server
Error   84  error LNK2001: unresolved external symbol "public: static void __cdecl std::_String_base::_Xlen(void)" (?_Xlen@_String_base@std@@SAXXZ) D:\server\mysqlpp.lib(sqlstream.obj)    server
Error   85  error LNK2001: unresolved external symbol "public: static void __cdecl std::_String_base::_Xlen(void)" (?_Xlen@_String_base@std@@SAXXZ) D:\server\mysqlpp.lib(field_types.obj)  server
Error   86  error LNK2001: unresolved external symbol "public: static void __cdecl std::_String_base::_Xlen(void)" (?_Xlen@_String_base@std@@SAXXZ) D:\server\mysqlpp.lib(stadapter.obj)    server
Error   87  error LNK2001: unresolved external symbol "public: static void __cdecl std::_String_base::_Xlen(void)" (?_Xlen@_String_base@std@@SAXXZ) D:\server\mysqlpp.lib(manip.obj)    server
Error   88  error LNK2001: unresolved external symbol "public: static void __cdecl std::_String_base::_Xlen(void)" (?_Xlen@_String_base@std@@SAXXZ) D:\server\mysqlpp.lib(utility.obj)  server
Error   89  error LNK2001: unresolved external symbol "public: static void __cdecl std::_String_base::_Xlen(void)" (?_Xlen@_String_base@std@@SAXXZ) D:\server\mysqlpp.lib(datetime.obj) server
Error   90  error LNK2001: unresolved external symbol "public: static void __cdecl std::_String_base::_Xlen(void)" (?_Xlen@_String_base@std@@SAXXZ) D:\server\mysqlpp.lib(type_info.obj)    server
Error   91  error LNK2001: unresolved external symbol "public: static void __cdecl std::_String_base::_Xlen(void)" (?_Xlen@_String_base@std@@SAXXZ) D:\server\mysqlpp.lib(vallist.obj)  server
Error   92  error LNK2001: unresolved external symbol "public: static void __cdecl std::_String_base::_Xlen(void)" (?_Xlen@_String_base@std@@SAXXZ) D:\server\mysqlpp.lib(field_names.obj)  server
Error   93  error LNK2001: unresolved external symbol "public: static void __cdecl std::_String_base::_Xlen(void)" (?_Xlen@_String_base@std@@SAXXZ) D:\server\mysqlpp.lib(query.obj)    server
Error   94  error LNK2001: unresolved external symbol "public: static void __cdecl std::_String_base::_Xlen(void)" (?_Xlen@_String_base@std@@SAXXZ) D:\server\mysqlpp.lib(dbdriver.obj) server
Error   95  error LNK2001: unresolved external symbol "public: static void __cdecl std::_String_base::_Xlen(void)" (?_Xlen@_String_base@std@@SAXXZ) D:\server\mysqlpp.lib(tcp_connection.obj)   server

VS2012标准库定义的运行时符号是否与VS2008提供的运行符号不同?

2 个答案:

答案 0 :(得分:2)

您看到的问题是由于STL和作为C ++一部分的其他库的差异。您可以尝试以下链接器开关:

/NODEFAULTLIB[:library]

在VS2008一侧构建时,如果你不能这样做,那你就不走运了。基本上你要做的就是摆脱标准库,从而将解析它们的任务委托给后来使用生成的静态.lib的链接器。

我应该补充一点,您还需要确保只使用收件人库知道的功能。

答案 1 :(得分:0)

MS有时会改变标准库函数的实现。我只需修复一个类似的问题,其中std :: _ St​​ring_base :: _ Xran()和Xlen的调用约定已从thiscall切换到cdecl。你必须找出不同版本之间发生的事情。然后可以通过包装器修复此问题,这些包装器使用所需的调用约定和名称修饰导出函数并重定向到新实现。

#include <string>

namespace std2008
{
class _String_base_2008
{ 
    public:
        __declspec(dllexport) void _Xlen2008(void) const; 
        __declspec(dllexport) void _Xran2008(void) const; 
};
};

void std2008::_String_base_2008::_Xran2008 () const
{
    std::_String_base::_Xran ();
}

void std2008::_String_base_2008::_Xlen2008 () const
{
    std::_String_base::_Xlen ();
}

将此代码保存为&#34; compat.cpp&#34;并用

编译
cl /D_DLL_EXPORT /EHsc /LD compat.cpp /link

现在让我们检查一下已创建的lib文件:

dumpbin /exports compat.lib

就我而言,它看起来像这样:

Dump of file compat.lib

File Type: LIBRARY

     Exports

       ordinal    name

                  ?_Xlen2008@_String_base_2008@std2008@@QBEXXZ (public: void __thiscall std2008::_String_base_2008::_Xlen2008(void)const )
                  ?_Xran2008@_String_base_2008@std2008@@QBEXXZ (public: void __thiscall std2008::_String_base_2008::_Xran2008(void)const )

查看链接器中有关缺失符号的错误时,您会看到所需的装饰。在你的情况下它&#34;?_ Xran @ _String_base @std @@ SAXXZ&#34;和&#34;?_ Xlen @ _String_base @ std @@ SAXXZ&#34;

最后一步是告诉链接器创建一个库,使用链接器错误中的符号和从dumpbin获取的名称将标准修饰名称映射到另一个名称。

cl /EHsc /LD compat.cpp /link /export:_Xran@_String_base@std@@SAXXZ=?_Xran2008@_String_base_2008@std2008@@QBEXXZ /export:?_Xlen@_String_base@std@@SAXXZ=?_Xlen2008@_String_base_2008@std2008@@QBEXXZ

必须为链接器抱怨的所有函数执行类似的重定向器。

现在添加&#34; compat.lib&#34;库作为项目的附加库和 现在它应该成功链接。