链接到多线程调试 DLL 库时出现链接错误

Posted

技术标签:

【中文标题】链接到多线程调试 DLL 库时出现链接错误【英文标题】:Linking error while linking to Multi-threaded Debug DLL library 【发布时间】:2013-05-16 12:06:14 【问题描述】:

我正在尝试将一个空项目与 PoDoFo 库 (.lib) 链接,该库是使用带有 多线程调试 DLL (/MDd) 的 VS 项目构建的> 设置。 当我尝试在另一个项目中链接该库时,无论我对这个 .lib 使用什么 代码生成 选项,我都会得到:

1>Linking...
1>libcmtd.lib(dbgheap.obj) : error LNK2005: __heap_alloc already defined in LIBCMT.lib(malloc.obj)
1>libcmtd.lib(dbgheap.obj) : error LNK2005: __recalloc already defined in LIBCMT.lib(recalloc.obj)
1>libcmtd.lib(dbgheap.obj) : error LNK2005: __msize already defined in LIBCMT.lib(msize.obj)
1>libcmtd.lib(malloc.obj) : error LNK2005: _V6_HeapAlloc already defined in LIBCMT.lib(malloc.obj)
1>libcmtd.lib(dbghook.obj) : error LNK2005: __crt_debugger_hook already defined in LIBCMT.lib(dbghook.obj)
1>libcmtd.lib(sbheap.obj) : error LNK2005: __get_sbh_threshold already defined in LIBCMT.lib(sbheap.obj)
1>libcmtd.lib(sbheap.obj) : error LNK2005: __set_sbh_threshold already defined in LIBCMT.lib(sbheap.obj)
1>libcmtd.lib(sbheap.obj) : error LNK2005: __set_amblksiz already defined in LIBCMT.lib(sbheap.obj)
1>libcmtd.lib(sbheap.obj) : error LNK2005: __get_amblksiz already defined in LIBCMT.lib(sbheap.obj)
1>libcmtd.lib(sbheap.obj) : error LNK2005: ___sbh_heap_init already defined in LIBCMT.lib(sbheap.obj)
1>libcmtd.lib(sbheap.obj) : error LNK2005: ___sbh_find_block already defined in LIBCMT.lib(sbheap.obj)
1>libcmtd.lib(sbheap.obj) : error LNK2005: ___sbh_free_block already defined in LIBCMT.lib(sbheap.obj)
1>libcmtd.lib(sbheap.obj) : error LNK2005: ___sbh_alloc_block already defined in LIBCMT.lib(sbheap.obj)
1>libcmtd.lib(sbheap.obj) : error LNK2005: ___sbh_alloc_new_region already defined in LIBCMT.lib(sbheap.obj)
1>libcmtd.lib(sbheap.obj) : error LNK2005: ___sbh_alloc_new_group already defined in LIBCMT.lib(sbheap.obj)
1>libcmtd.lib(sbheap.obj) : error LNK2005: ___sbh_resize_block already defined in LIBCMT.lib(sbheap.obj)
1>libcmtd.lib(sbheap.obj) : error LNK2005: ___sbh_heapmin already defined in LIBCMT.lib(sbheap.obj)
1>libcmtd.lib(sbheap.obj) : error LNK2005: ___sbh_heap_check already defined in LIBCMT.lib(sbheap.obj)
1>libcmtd.lib(sbheap.obj) : error LNK2005: ___sbh_pHeaderDefer already defined in LIBCMT.lib(sbheap.obj)
1>libcmtd.lib(isctype.obj) : error LNK2005: __isctype_l already defined in LIBCMT.lib(isctype.obj)
1>libcmtd.lib(isctype.obj) : error LNK2005: __isctype already defined in LIBCMT.lib(isctype.obj)
1>msvcrtd.lib(ti_inst.obj) : error LNK2005: "private: __thiscall type_info::type_info(class type_info const &)" (??0type_info@@AAE@ABV0@@Z) already defined in LIBCMT.lib(typinfo.obj)
1>msvcrtd.lib(ti_inst.obj) : error LNK2005: "private: class type_info & __thiscall type_info::operator=(class type_info const &)" (??4type_info@@AAEAAV0@ABV0@@Z) already defined in LIBCMT.lib(typinfo.obj)
1>msvcrtd.lib(MSVCR90D.dll) : error LNK2005: __invalid_parameter already defined in LIBCMT.lib(invarg.obj)
1>msvcrtd.lib(MSVCR90D.dll) : error LNK2005: __CrtDbgReportW already defined in libcmtd.lib(dbgrptw.obj)
1>msvcrtd.lib(MSVCR90D.dll) : error LNK2005: "public: virtual __thiscall std::exception::~exception(void)" (??1exception@std@@UAE@XZ) already defined in LIBCMT.lib(stdexcpt.obj)
1>msvcrtd.lib(MSVCR90D.dll) : error LNK2005: "public: __thiscall std::exception::exception(void)" (??0exception@std@@QAE@XZ) already defined in LIBCMT.lib(stdexcpt.obj)
1>msvcrtd.lib(MSVCR90D.dll) : error LNK2005: "public: __thiscall std::exception::exception(class std::exception const &)" (??0exception@std@@QAE@ABV01@@Z) already defined in LIBCMT.lib(stdexcpt.obj)
1>msvcrtd.lib(MSVCR90D.dll) : error LNK2005: "public: __thiscall std::exception::exception(char const * const &)" (??0exception@std@@QAE@ABQBD@Z) already defined in LIBCMT.lib(stdexcpt.obj)
1>msvcrtd.lib(MSVCR90D.dll) : error LNK2005: ___iob_func already defined in libcmtd.lib(_file.obj)
1>msvcrtd.lib(MSVCR90D.dll) : error LNK2005: _free already defined in LIBCMT.lib(free.obj)
1>msvcrtd.lib(MSVCR90D.dll) : error LNK2005: _malloc already defined in LIBCMT.lib(malloc.obj)
1>msvcrtd.lib(MSVCR90D.dll) : error LNK2005: _realloc already defined in LIBCMT.lib(realloc.obj)
1>msvcrtd.lib(MSVCR90D.dll) : error LNK2005: _wcstombs already defined in libcmtd.lib(wcstombs.obj)
1>msvcrtd.lib(MSVCR90D.dll) : error LNK2005: _wcslen already defined in LIBCMT.lib(wcslen.obj)
1>msvcrtd.lib(MSVCR90D.dll) : error LNK2005: _strtol already defined in LIBCMT.lib(strtol.obj)
1>msvcrtd.lib(MSVCR90D.dll) : error LNK2005: _isdigit already defined in LIBCMT.lib(_ctype.obj)
1>msvcrtd.lib(MSVCR90D.dll) : error LNK2005: _strncmp already defined in LIBCMT.lib(strncmp.obj)
1>msvcrtd.lib(MSVCR90D.dll) : error LNK2005: _fopen already defined in libcmtd.lib(fopen.obj)
1>msvcrtd.lib(MSVCR90D.dll) : error LNK2005: _fclose already defined in libcmtd.lib(fclose.obj)
1>msvcrtd.lib(MSVCR90D.dll) : error LNK2005: _fread already defined in libcmtd.lib(fread.obj)
1>msvcrtd.lib(MSVCR90D.dll) : error LNK2005: _fseek already defined in libcmtd.lib(fseek.obj)
1>msvcrtd.lib(MSVCR90D.dll) : error LNK2005: _ftell already defined in libcmtd.lib(ftell.obj)
1>msvcrtd.lib(MSVCR90D.dll) : error LNK2005: __vscprintf already defined in libcmtd.lib(vsprintf.obj)
1>msvcrtd.lib(MSVCR90D.dll) : error LNK2005: _fflush already defined in libcmtd.lib(fflush.obj)
1>msvcrtd.lib(MSVCR90D.dll) : error LNK2005: __strnicmp already defined in LIBCMT.lib(strnicmp.obj)
1>msvcrtd.lib(MSVCR90D.dll) : error LNK2005: _sprintf already defined in libcmtd.lib(sprintf.obj)
1>msvcrtd.lib(MSVCR90D.dll) : error LNK2005: _memmove already defined in LIBCMT.lib(memmove.obj)
1>msvcrtd.lib(MSVCR90D.dll) : error LNK2005: _strftime already defined in LIBCMT.lib(strftime.obj)
1>msvcrtd.lib(MSVCR90D.dll) : error LNK2005: ___timezone already defined in LIBCMT.lib(timeset.obj)
1>msvcrtd.lib(MSVCR90D.dll) : error LNK2005: __tzset already defined in LIBCMT.lib(tzset.obj)
1>msvcrtd.lib(MSVCR90D.dll) : error LNK2005: _exit already defined in LIBCMT.lib(crt0dat.obj)
1>msvcrtd.lib(MSVCR90D.dll) : error LNK2005: _isspace already defined in LIBCMT.lib(_ctype.obj)
1>msvcrtd.lib(MSVCR90D.dll) : error LNK2005: _getenv already defined in LIBCMT.lib(getenv.obj)
1>msvcrtd.lib(MSVCR90D.dll) : error LNK2005: __stricmp already defined in LIBCMT.lib(stricmp.obj)
1>msvcrtd.lib(MSVCR90D.dll) : error LNK2005: _isxdigit already defined in LIBCMT.lib(_ctype.obj)
1>msvcrtd.lib(MSVCR90D.dll) : error LNK2005: _strstr already defined in libcmtd.lib(strstr.obj)
1>msvcprtd.lib(MSVCP90D.dll) : error LNK2005: "public: __thiscall std::allocator<char>::allocator<char>(void)" (??0?$allocator@D@std@@QAE@XZ) already defined in TestPoDoFo.obj
1>msvcprtd.lib(MSVCP90D.dll) : error LNK2005: "public: __thiscall std::allocator<char>::allocator<char>(class std::allocator<char> const &)" (??0?$allocator@D@std@@QAE@ABV01@@Z) already defined in TestPoDoFo.obj

如果有什么用,我也发过这个:

/Od /I "..\Podofo.Include\\" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_UNICODE" /D "UNICODE" /Gm /EHsc /RTC1 /MTd /Yu"stdafx.h" /Fp"Debug\TestPoDoFo.pch" /Fo"Debug\\" /Fd"Debug\vc90.pdb" /W3 /nologo /c /ZI /TP /errorReport:prompt

与.lib链接的测试项目(.exe)不应该也是多线程调试DLL(/MDd)??

【问题讨论】:

【参考方案1】:

一般来说,您的所有项目都应该使用多线程调试 DLL (/MDd)

【讨论】:

我能说什么...我错过了一个子项目..! x(

以上是关于链接到多线程调试 DLL 库时出现链接错误的主要内容,如果未能解决你的问题,请参考以下文章

从 dll 导出 std::vector 时出现链接错误

与 DLL 链接时出现“‘atexit’的多重定义”

安装Qt creator时出现 无法定位程序输入点_except1 于动态链接库MSVCR120.dll上

打开软件时出现无法定位程序输入点 GetTickCount64 于动态链接库 KERNEL32.dll 上。

Delphi 软件包安装错误:动态链接库 (DLL) 初始化例程失败

包含omniture库时出现链接器错误