关于这样的错误 libcpmtd.lib(string.obj) : error LNK2005: "public: void __thiscall

本文解决了一个在Visual C++ 2008环境中从动态库转换为静态库后出现的链接错误问题。主要原因是项目设置中运行时库选项不一致导致重复定义错误。

VC2008下 在一个动态库工程中, 改成了编程静态库, 成功编译, 但使用静态库的工程编译时就出现下面一堆连接错误.

 

经过查找 解决方法如下:

说是因为 Project->C/C++->Code Generation->Runtime Library 这个选项,LIB和主程序(EXE)里选择的不一致引起的。后来改成一样就好了。

 

把exe工程 改为/MTD(因为Lib工程是选择/MTD的) 编译还是错误

于是 把EXE工程和Lib工程都选择为/MDD 成功编译

 

 

1>------ Build started: Project: Inceku, Configuration: Debug Win32 ------
1>Linking...
1>msvcprtd.lib(MSVCP90D.dll) : error LNK2005: "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> >(void)" (??1?
$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@XZ) already 
defined in CrissCross.lib(core_io_reader.obj)
1>msvcprtd.lib(MSVCP90D.dll) : error LNK2005: "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> >(char const *)" (??0?
$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@PBD@Z) 
already defined in CrissCross.lib(debug.obj)
1>msvcprtd.lib(MSVCP90D.dll) : error LNK2005: "public: static unsigned int 
__cdecl std::char_traits<char>::length(char const *)" (?length@?
$char_traits@D@std@@SAIPBD@Z) already defined in CrissCross.lib(debug.obj)
1>msvcprtd.lib(MSVCP90D.dll) : error LNK2005: "public: class 
std::basic_string<char,struct std::char_traits<char>,class 
std::allocator<char> > & __thiscall std::basic_string<char,struct 
std::char_traits<char>,class std::allocator<char> >::operator=(char const 
*)" (??4?$basic_string@DU?$char_traits@D@std@@V?
$allocator@D@2@@std@@QAEAAV01@PBD@Z) already defined in 
CrissCross.lib(core_socket.obj)
1>LIBCMTD.lib(crt0dat.obj) : error LNK2005: _exit already defined in 
MSVCRTD.lib(MSVCR90D.dll)
1>LIBCMTD.lib(crt0dat.obj) : error LNK2005: __exit already defined in 
MSVCRTD.lib(MSVCR90D.dll)
1>LIBCMTD.lib(crt0dat.obj) : error LNK2005: __cexit already defined in 
MSVCRTD.lib(MSVCR90D.dll)
1>LIBCMTD.lib(crt0dat.obj) : error LNK2005: __amsg_exit already defined in 
MSVCRTD.lib(MSVCR90D.dll)
1>LIBCMTD.lib(crt0dat.obj) : error LNK2005: __initterm_e already defined in 
MSVCRTD.lib(MSVCR90D.dll)
1>LIBCMTD.lib(tidtable.obj) : error LNK2005: __encode_pointer already 
defined in MSVCRTD.lib(MSVCR90D.dll)
1>LIBCMTD.lib(tidtable.obj) : error LNK2005: __decode_pointer already 
defined in MSVCRTD.lib(MSVCR90D.dll)
1>LIBCMTD.lib(dbgheap.obj) : error LNK2005: __malloc_dbg already defined in 
MSVCRTD.lib(MSVCR90D.dll)
1>LIBCMTD.lib(dbgheap.obj) : error LNK2005: __free_dbg already defined in 
MSVCRTD.lib(MSVCR90D.dll)
1>LIBCMTD.lib(dbgheap.obj) : error LNK2005: __CrtDumpMemoryLeaks already 
defined in MSVCRTD.lib(MSVCR90D.dll)
1>LIBCMTD.lib(dbgheap.obj) : error LNK2005: __CrtSetCheckCount already 
defined in MSVCRTD.lib(MSVCR90D.dll)
1>LIBCMTD.lib(crt0init.obj) : error LNK2005: ___xi_a already defined in 
MSVCRTD.lib(cinitexe.obj)
1>LIBCMTD.lib(crt0init.obj) : error LNK2005: ___xi_z already defined in 
MSVCRTD.lib(cinitexe.obj)
1>LIBCMTD.lib(crt0init.obj) : error LNK2005: ___xc_a already defined in 
MSVCRTD.lib(cinitexe.obj)
1>LIBCMTD.lib(crt0init.obj) : error LNK2005: ___xc_z already defined in 
MSVCRTD.lib(cinitexe.obj)
1>LIBCMTD.lib(hooks.obj) : error LNK2005: "void __cdecl terminate(void)" (?
terminate@@YAXXZ) already defined in MSVCRTD.lib(MSVCR90D.dll)
1>LIBCMTD.lib(winxfltr.obj) : error LNK2005: __XcptFilter already defined 
in MSVCRTD.lib(MSVCR90D.dll)
1>LIBCMTD.lib(invarg.obj) : error LNK2005: __invalid_parameter already 
defined in MSVCRTD.lib(MSVCR90D.dll)
1>LIBCMTD.lib(invarg.obj) : error LNK2005: __invoke_watson already defined 
in MSVCRTD.lib(MSVCR90D.dll)
1>LIBCMTD.lib(setlocal.obj) : error LNK2005: __configthreadlocale already

为什么debug编译报错:已启动重新生成… 1>------ 已启动全部重新生成: 项目: UsrAcqDrv, 配置: Debug x64 ------ 1>stdafx.cpp 1>UsrAcqDrv.cpp 1>D:\code\SherLock_UsrAcqDrv\Sherlock7\include\IKapBoard.h(513,1): warning C4819: 该文件包含不能在当前代码页(936)中表示的字符。请将该文件保存为 Unicode 格式以防止数据丢失 1>D:\code\SherLock_UsrAcqDrv\Sherlock7\include\IKapBoard.h(1375,1): warning C4819: 该文件包含不能在当前代码页(936)中表示的字符。请将该文件保存为 Unicode 格式以防止数据丢失 1>D:\code\SherLock_UsrAcqDrv\Sherlock7\include\IKapC.h(1,1): warning C4819: 该文件包含不能在当前代码页(936)中表示的字符。请将该文件保存为 Unicode 格式以防止数据丢失 1>D:\code\SherLock_UsrAcqDrv\Sherlock7\include\IKapCType.h(1,1): warning C4819: 该文件包含不能在当前代码页(936)中表示的字符。请将该文件保存为 Unicode 格式以防止数据丢失 1>D:\code\SherLock_UsrAcqDrv\Sherlock7\include\IKapC.h(1312,1): warning C4819: 该文件包含不能在当前代码页(936)中表示的字符。请将该文件保存为 Unicode 格式以防止数据丢失 1>D:\code\SherLock_UsrAcqDrv\Sherlock7\UsrAcqDrv\ITKDeviceManager.h(229,23): warning C4101: “tIKei”: 未引用的局部变量 1>D:\code\SherLock_UsrAcqDrv\Sherlock7\UsrAcqDrv\ITKDeviceManager.h(794,31): warning C4244: “=”: 从“int64_t”转换到“int”,可能丢失数据 1>D:\code\SherLock_UsrAcqDrv\Sherlock7\UsrAcqDrv\ITKDeviceManager.h(798,32): warning C4244: “=”: 从“int64_t”转换到“int”,可能丢失数据 1>D:\code\SherLock_UsrAcqDrv\Sherlock7\UsrAcqDrv\UsrAcqDrv.cpp(143,23): warning C4018: “<”: 有符号/无符号不匹配 1>D:\code\SherLock_UsrAcqDrv\Sherlock7\UsrAcqDrv\UsrAcqDrv.cpp(193,37): warning C4267: “=”: 从“size_t”转换到“int”,可能丢失数据 1>D:\code\SherLock_UsrAcqDrv\Sherlock7\UsrAcqDrv\UsrAcqDrv.cpp(356,63): warning C4267: “=”: 从“size_t”转换到“int”,可能丢失数据 1>UsrAcqDrvDll.cpp 1>正在生成代码... 1> 正在创建库 x64\Debug_v80\UsrAcqDrv.lib 和对象 x64\Debug_v80\UsrAcqDrv.exp 1>libcpmtd.lib(xwcsxfrm.obj) : error LNK2001: 无法解析的外部符号 _free_dbg 1>libcpmtd.lib(StlCompareStringA.obj) : error LNK2001: 无法解析的外部符号 _free_dbg 1>libcpmtd.lib(locale.obj) : error LNK2001: 无法解析的外部符号 _free_dbg 1>libcpmtd.lib(StlLCMapStringA.obj) : error LNK2001: 无法解析的外部符号 _free_dbg 1>libcpmtd.lib(wlocale.obj) : error LNK2001: 无法解析的外部符号 _free_dbg 1>libcpmtd.lib(xlocale.obj) : error LNK2001: 无法解析的外部符号 _free_dbg 1>UsrAcqDrv.obj : error LNK2001: 无法解析的外部符号 _free_dbg 1>libcpmtd.lib(mutex.obj) : error LNK2001: 无法解析的外部符号 _free_dbg 1>libcpmtd.lib(cond.obj) : error LNK2001: 无法解析的外部符号 _free_dbg 1>libcpmtd.lib(locale0.obj) : error LNK2001: 无法解析的外部符号 _free_dbg 1>libcpmtd.lib(wlocale.obj) : error LNK2001: 无法解析的外部符号 _malloc_dbg 1>libcpmtd.lib(xlocale.obj) : error LNK2001: 无法解析的外部符号 _malloc_dbg 1>libcpmtd.lib(xwcsxfrm.obj) : error LNK2001: 无法解析的外部符号 _malloc_dbg 1>libcpmtd.lib(StlCompareStringA.obj) : error LNK2001: 无法解析的外部符号 _malloc_dbg 1>UsrAcqDrv.obj : error LNK2001: 无法解析的外部符号 _malloc_dbg 1>libcpmtd.lib(locale0.obj) : error LNK2001: 无法解析的外部符号 _malloc_dbg 1>libcpmtd.lib(locale.obj) : error LNK2001: 无法解析的外部符号 _malloc_dbg 1>libcpmtd.lib(StlLCMapStringA.obj) : error LNK2001: 无法解析的外部符号 _malloc_dbg 1>libcpmtd.lib(wlocale.obj) : error LNK2001: 无法解析的外部符号 _CrtDbgReport 1>libcpmtd.lib(xlocale.obj) : error LNK2001: 无法解析的外部符号 _CrtDbgReport 1>UsrAcqDrv.obj : error LNK2001: 无法解析的外部符号 _CrtDbgReport 1>libcpmtd.lib(xtime.obj) : error LNK2001: 无法解析的外部符号 _CrtDbgReport 1>libcpmtd.lib(thread0.obj) : error LNK2001: 无法解析的外部符号 _CrtDbgReport 1>libcpmtd.lib(locale.obj) : error LNK2001: 无法解析的外部符号 _CrtDbgReport 1>UsrAcqDrv.obj : error LNK2019: 无法解析的外部符号 "__declspec(dllimport) public: bool __cdecl std::less<int>::operator()(int const &,int const &)const " (__imp_??R?$less@H@std@@QEBA_NAEBH0@Z),函数 "bool __cdecl std::_Debug_lt_pred<struct std::less<int> const &,int const &,int const &,0>(struct std::less<int> const &,int const &,int const &)" (??$_Debug_lt_pred@AEBU?$less@H@std@@AEBHAEBH$0A@@std@@YA_NAEBU?$less@H@0@AEBH1@Z) 中引用了该符号 1>libcpmtd.lib(wlocale.obj) : error LNK2001: 无法解析的外部符号 _calloc_dbg 1>libcpmtd.lib(xlocale.obj) : error LNK2001: 无法解析的外部符号 _calloc_dbg 1>libcpmtd.lib(mutex.obj) : error LNK2001: 无法解析的外部符号 _calloc_dbg 1>libcpmtd.lib(cond.obj) : error LNK2001: 无法解析的外部符号 _calloc_dbg 1>libcpmtd.lib(_tolower.obj) : error LNK2001: 无法解析的外部符号 _calloc_dbg 1>libcpmtd.lib(locale.obj) : error LNK2001: 无法解析的外部符号 _calloc_dbg 1>libcpmtd.lib(_tolower.obj) : error LNK2019: 无法解析的外部符号 _wcsdup_dbg,函数 _Getctype 中引用了该符号 1>libcpmtd.lib(xstrcoll.obj) : error LNK2001: 无法解析的外部符号 _wcsdup_dbg 1>libcpmtd.lib(locale.obj) : error LNK2019: 无法解析的外部符号 _realloc_dbg,函数 "private: static void __cdecl std::locale::_Locimp::_Locimp_Addfac(class std::locale::_Locimp *,class std::locale::facet *,unsigned __int64)" (?_Locimp_Addfac@_Locimp@locale@std@@CAXPEAV123@PEAVfacet@23@_K@Z) 中引用了该符号 1>libcpmtd.lib(StlLCMapStringA.obj) : error LNK2019: 无法解析的外部符号 _CrtDbgReportW,函数 _freea_crt 中引用了该符号 1>libcpmtd.lib(xmbtowc.obj) : error LNK2001: 无法解析的外部符号 _CrtDbgReportW 1>libcpmtd.lib(StlCompareStringA.obj) : error LNK2001: 无法解析的外部符号 _CrtDbgReportW 1>x64\Debug_v80\UsrAcqDrv.dll : fatal error LNK1120: 8 个无法解析的外部命令 1>已完成生成项目“UsrAcqDrv.vcxproj”的操作 - 失败。 ========== 全部重新生成: 成功 0 个,失败 1 个,跳过 0 个 ========== release编译就没问题
最新发布
11-14
1>LINK : warning LNK4098: 默认库“LIBCMT”与其他库的使用冲突;请使用 /NODEFAULTLIB:library 1>UsrAcqDrv.obj : error LNK2019: 无法解析的外部符号 _invalid_parameter,函数 "void * __cdecl std::_Allocate_manually_vector_aligned<struct std::_Default_allocate_traits>(unsigned __int64)" (??$_Allocate_manually_vector_aligned@U_Default_allocate_traits@std@@@std@@YAPEAX_K@Z) 中引用了该符号 1>libcpmtd.lib(xtime.obj) : error LNK2001: 无法解析的外部符号 _invalid_parameter 1>libcpmtd.lib(thread0.obj) : error LNK2001: 无法解析的外部符号 _invalid_parameter 1>UsrAcqDrv.obj : error LNK2019: 无法解析的外部符号 _CrtDbgReport,函数 "void * __cdecl std::_Allocate_manually_vector_aligned<struct std::_Default_allocate_traits>(unsigned __int64)" (??$_Allocate_manually_vector_aligned@U_Default_allocate_traits@std@@@std@@YAPEAX_K@Z) 中引用了该符号 1>libcpmtd.lib(xtime.obj) : error LNK2001: 无法解析的外部符号 _CrtDbgReport 1>libcpmtd.lib(thread0.obj) : error LNK2001: 无法解析的外部符号 _CrtDbgReport 1>UsrAcqDrv.obj : error LNK2019: 无法解析的外部符号 "__declspec(dllimport) public: bool __cdecl std::less<int>::operator()(int const &,int const &)const " (__imp_??R?$less@H@std@@QEBA_NAEBH0@Z),函数 "bool __cdecl std::_Debug_lt_pred<struct std::less<int> const &,int const &,int const &,0>(struct std::less<int> const &,int const &,int const &)" (??$_Debug_lt_pred@AEBU?$less@H@std@@AEBHAEBH$0A@@std@@YA_NAEBU?$less@H@0@AEBH1@Z) 中引用了该符号 1>libcpmtd.lib(mutex.obj) : error LNK2019: 无法解析的外部符号 _calloc_dbg,函数 _Mtx_init 中引用了该符号 1>libcpmtd.lib(cond.obj) : error LNK2001: 无法解析的外部符号 _calloc_dbg 1>libcpmtd.lib(mutex.obj) : error LNK2019: 无法解析的外部符号 _free_dbg,函数 _Mtx_destroy 中引用了该符号 1>libcpmtd.lib(cond.obj) : error LNK2001: 无法解析的外部符号 _free_dbg 1>x64\Debug_v80\UsrAcqDrv.dll : fatal error LNK1120: 5 个无法解析的外部命令 1>已完成生成项目“UsrAcqDrv.vcxproj”的操作 - 失败。
11-13
1>msvcrt.lib(ti_inst.obj) : error LNK2005: "private: __cdecl type_info::type_info(class type_info const &)" (??0type_info@@AEAA@AEBV0@@Z) 已经在 LIBCMTD.lib(typinfo.obj) 中定义 1>msvcrt.lib(ti_inst.obj) : error LNK2005: "private: class type_info & __cdecl type_info::operator=(class type_info const &)" (??4type_info@@AEAAAEAV0@AEBV0@@Z) 已经在 LIBCMTD.lib(typinfo.obj) 中定义 1>msvcrt.lib(MSVCR100.dll) : error LNK2005: atof 已经在 LIBCMTD.lib(atof.obj) 中定义 1>msvcrt.lib(MSVCR100.dll) : error LNK2005: sprintf_s 已经在 LIBCMTD.lib(sprintf.obj) 中定义 1>msvcrt.lib(MSVCR100.dll) : error LNK2005: printf 已经在 LIBCMTD.lib(printf.obj) 中定义 1>msvcrt.lib(MSVCR100.dll) : error LNK2005: free 已经在 LIBCMTD.lib(dbgfree.obj) 中定义 1>msvcrt.lib(MSVCR100.dll) : error LNK2005: malloc 已经在 LIBCMTD.lib(dbgmalloc.obj) 中定义 1>msvcrt.lib(MSVCR100.dll) : error LNK2005: fclose 已经在 LIBCMTD.lib(fclose.obj) 中定义 1>msvcrt.lib(MSVCR100.dll) : error LNK2005: fputc 已经在 LIBCMTD.lib(fputc.obj) 中定义 1>msvcrt.lib(MSVCR100.dll) : error LNK2005: fopen_s 已经在 LIBCMTD.lib(fopen.obj) 中定义 1>msvcrt.lib(MSVCR100.dll) : error LNK2005: fgetc 已经在 LIBCMTD.lib(fgetc.obj) 中定义 1>msvcrt.lib(MSVCR100.dll) : error LNK2005: fopen 已经在 LIBCMTD.lib(fopen.obj) 中定义 1>msvcrt.lib(MSVCR100.dll) : error LNK2005: strstr 已经在 LIBCMTD.lib(strstr.obj) 中定义 1>msvcrt.lib(MSVCR100.dll) : error LNK2005: strcpy_s 已经在 LIBCMTD.lib(strcpy_s.obj) 中定义 1>msvcrt.lib(MSVCR100.dll) : error LNK2005: memcpy_s 已经在 LIBCMTD.lib(memcpy_s.obj) 中定义 1>msvcrt.lib(MSVCR100.dll) : error LNK2005: memmove_s 已经在 LIBCMTD.lib(memmove_s.obj) 中定义 1>msvcrt.lib(MSVCR100.dll) : error LNK2005: wcslen 已经在 LIBCMTD.lib(wcslen.obj) 中定义 1>msvcrt.lib(MSVCR100.dll) : error LNK2005: memmove 已经在 LIBCMTD.lib(memcpy.obj) 中定义 1>msvcrt.lib(MSVCR100.dll) : error LNK2005: vsprintf_s 已经在 LIBCMTD.lib(vsnprnc.obj) 中定义 1>msvcrt.lib(MSVCR100.dll) : error LNK2005: "public: __cdecl std::exception::exception(char const * const &)" (??0exception@std@@QEAA@AEBQEBD@Z) 已经在 LIBCMTD.lib(stdexcpt.obj) 中定义 1>msvcrt.lib(MSVCR100.dll) : error LNK2005: "public: virtual __cdecl std::exception::~exception(void)" (??1exception@std@@UEAA@XZ) 已经在 LIBCMTD.lib(stdexcpt.obj) 中定义 1>msvcrt.lib(MSVCR100.dll) : error LNK2005: "public: __cdecl std::exception::exception(class std::exception const &)" (??0exception@std@@QEAA@AEBV01@@Z) 已经在 LIBCMTD.lib(stdexcpt.obj) 中定义 1>msvcrt.lib(MSVCR100.dll) : error LNK2005: _stricmp 已经在 LIBCMTD.lib(stricmp.obj) 中定义 1>msvcrt.lib(MSVCR100.dll) : error LNK2005: getc 已经在 LIBCMTD.lib(fgetc.obj) 中定义 1>msvcrt.lib(MSVCR100.dll) : error LNK2005: system 已经在 LIBCMTD.lib(system.obj) 中定义 1>msvcrt.lib(MSVCR100.dll) : error LNK2005: getenv_s 已经在 LIBCMTD.lib(getenv.obj) 中定义 1>msvcrt.lib(MSVCR100.dll) : error LNK2005: atoi 已经在 LIBCMTD.lib(atox.obj) 中定义 1>msvcrt.lib(MSVCR100.dll) : error LNK2005: fwrite 已经在 LIBCMTD.lib(fwrite.obj) 中定义 1>msvcrt.lib(MSVCR100.dll) : error LNK2005: ftell 已经在 LIBCMTD.lib(ftell.obj) 中定义 1>msvcrt.lib(MSVCR100.dll) : error LNK2005: fseek 已经在 LIBCMTD.lib(fseek.obj) 中定义 1>msvcprt.lib(MSVCP100.dll) : error LNK2005: "void __cdecl std::_Xlength_error(char const *)" (?_Xlength_error@std@@YAXPEBD@Z) 已经在 libcpmtd.lib(xthrow.obj) 中定义 1>msvcprt.lib(MSVCP100.dll) : error LNK2005: "void __cdecl std::_Xout_of_range(char const *)" (?_Xout_of_range@std@@YAXPEBD@Z) 已经在 libcpmtd.lib(xthrow.obj) 中定义 1> 正在创建库 E:\Code\Work\diaoSlide\04-diaoSlide-HuaKuaiZuo\x64\Debug\/diaoSlide.lib 和对象 E:\Code\Work\diaoSlide\04-diaoSlide-HuaKuaiZuo\x64\Debug\/diaoSlide.exp 1>LIBCMTD.lib(crt0init.obj) : warning LNK4098: 默认库“msvcrt.lib”与其他库的使用冲突;请使用 /NODEFAULTLIB:library 1>E:\Code\Work\diaoSlide\04-diaoSlide-HuaKuaiZuo\x64\Debug\diaoSlide.dll : fatal error LNK1169: 找到一个或多个多重定义的符号 1>已完成生成项目“GuideRail.vcxproj”的操作 - 失败。
06-07
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

sunxiaopengsun

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值