std::_String_alloc 析构函数链接器错误

时间:2021-04-28 08:28:45

标签: c++ c++11 visual-studio-2015

我有一个第三方静态库和两个 dll(比如,foo.dllbar.dll)。 bar.dllfoo.dll 链接。 bar.dll 显式实例化 std::basic_string 模板并继承 std::basic_string 类并将其导出。

我正在尝试将 static libfoo.dll 链接起来。但是在链接过程中,出现了与std::_String_alloc 析构函数相关的错误。错误如下:

Error LNK2005 "public: __cdecl std::_String_alloc > >::~_String_alloc > >(void)" (??1?$_String_alloc@U?$_String_base_types@_WV?$allocator@_W@std@@@std@@@std@@QEAA@XZ) 已经定义在bar.lib(bar.dll)

为了解决上述链接器错误(其中明确指出std::_String_alloc 析构函数有多个符号),我尝试声明显式实例化(extern 模板) 静态库中的em>如下:

extern template  std::_String_alloc< std::_String_base_types<wchar_t, class std::allocator<wchar_t> >>::~_String_alloc(void);

但是链接器错误仍然存​​在,并且抛出了如下新错误:

编译器生成的函数“std::_String_alloc<_Alloc_types>::~_String_alloc [with _Alloc_types=std::_String_base_types>]”无法显式实例化。

我的问题如下:

  1. 可以以及如何显式声明 std::_String_alloc 析构函数,以便可以抑制其隐式实例化(和符号)。

  2. 根据新生成的错误,如果 std::_String_alloc 无法显式实例化,那么如何解决链接器错误。我无法对 bar.dll 进行任何更改。 (由于符号已在 bar.dll 中定义,因此抛出错误)

如果有人能对模板 std::_String_alloc 有所了解就太好了(它是 std::basic_string 的基类,没有太多信息出现在 Internet 上。)以及为它抛出的新错误(编译器生成的函数无法显式实例化。)

其他std::basic_string 成员函数(包括std::basic_string 构造函数、析构函数和移动构造函数)存在链接器错误。我通过在静态库(extern 模板)中显式声明这些成员函数来解决这些问题。 Link

0 个答案:

没有答案
相关问题