第三方DLL导出STL符号致链接冲突,求可行解决方法
第三方DLL导出
std::vector<unsigned char>符号引发链接冲突问题 我正在开发一个依赖第三方DLL的项目,该DLL未知原因导出了std::vector<unsigned char>的大部分(非全部)符号,通过dumpbin.exe验证的结果如下:
$ dumpbin.exe -exports Problem.lib | grep 'std::vector' ??0?$vector@EV?$allocator@E@std@@@std@@QEAA@$$QEAV01@@Z (public: __cdecl std::vector<unsigned char,class std::allocator<unsigned char> >::vector<unsigned char,class std::allocator<unsigned char> >(class std::vector<unsigned char,class std::allocator<unsigned char> > &&)) ??0?$vector@EV?$allocator@E@std@@@std@@QEAA@$$QEAV01@AEBV?$allocator@E@1@@Z (public: __cdecl std::vector<unsigned char,class std::allocator<unsigned char> >::vector<unsigned char,class std::allocator<unsigned char> >(class std::vector<unsigned char,class std::allocator<unsigned char> > &&,class std::allocator<unsigned char> const &)) ??0?$vector@EV?$allocator@E@std@@@std@@QEAA@AEBV01@@Z (public: __cdecl std::vector<unsigned char,class std::allocator<unsigned char> >::vector<unsigned char,class std::allocator<unsigned char> >(class std::vector<unsigned char,class std::allocator<unsigned char> > const &)) ??0?$vector@EV?$allocator@E@std@@@std@@QEAA@AEBV01@AEBV?$allocator@E@1@@Z (public: __cdecl std::vector<unsigned char,class std::allocator<unsigned char> >::vector<unsigned char,class std::allocator<unsigned char> >(class std::vector<unsigned char,class std::allocator<unsigned char> > const &,class std::allocator<unsigned char> const &)) ??0?$vector@EV?$allocator@E@std@@@std@@QEAA@AEBV?$allocator@E@1@@Z (public: __cdecl std::vector<unsigned char,class std::allocator<unsigned char> >::vector<unsigned char,class std::allocator<unsigned char> >(class std::allocator<unsigned char> const &)) ??0?$vector@EV?$allocator@E@std@@@std@@QEAA@V?$initializer_list@E@1@AEBV?$allocator@E@1@@Z (public: __cdecl std::vector<unsigned char,class std::allocator<unsigned char> >::vector<unsigned char,class std::allocator<unsigned char> >(class std::initializer_list<unsigned char>,class std::allocator<unsigned char> const &)) ??0?$vector@EV?$allocator@E@std@@@std@@QEAA@XZ (public: __cdecl std::vector<unsigned char,class std::allocator<unsigned char> >::vector<unsigned char,class std::allocator<unsigned char> >(void)) ??0?$vector@EV?$allocator@E@std@@@std@@QEAA@_KAEBEAEBV?$allocator@E@1@@Z (public: __cdecl std::vector<unsigned char,class std::allocator<unsigned char> >::vector<unsigned char,class std::allocator<unsigned char> >(unsigned __int64,unsigned char const &,class std::allocator<unsigned char> const &)) ??0?$vector@EV?$allocator@E@std@@@std@@QEAA@_KAEBV?$allocator@E@1@@Z (public: __cdecl std::vector<unsigned char,class std::allocator<unsigned char> >::vector<unsigned char,class std::allocator<unsigned char> >(unsigned __int64,class std::allocator<unsigned char> const &)) ??1?$vector@EV?$allocator@E@std@@@std@@QEAA@XZ (public: __cdecl std::vector<unsigned char,class std::allocator<unsigned char> >::~vector<unsigned char,class std::allocator<unsigned char> >(void)) ...
当项目代码中使用std::vector<unsigned char>时,出现重复符号导致的链接失败错误:
Problem.lib(Problem.dll) : error LNK2005: "public: __cdecl std::vector<unsigned char,class std::allocator<unsigned char> >::~vector<unsigned char,class std::allocator<unsigned char> >(void)" (??1?$vector@EV?$allocator@E@std@@@std@@QEAA@XZ) already defined in Application.obj Creating library C:\Users\Parker\project\Application.lib and object C:\Users\Parker\Project\Application.exp C:\Users\Parker\project\Application.exe : fatal error LNK1169: one or more multiply defined symbols found
我无法获取该DLL的源代码,也无法从供应商处获取新版本,且供应商不会修复此问题。已尝试三种方法但均未成功:
- 修改存根.lib文件移除相关导出符号,暂未找到可行方法;
- 使用C++11的
extern template特性复用DLL中的实现,尝试未成功; - 在应用代码中完全避免使用
std::vector<unsigned char>,该方案虽极端但短期可能省力。
现寻求该特殊问题的可行解决途径。
内容的提问来源于stack exchange,提问作者Parker Coates
相关产品推荐
相关产品推荐

