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

在将一个工程从动态库改为静态库后,使用该静态库的工程出现链接错误。解决方法是统一设置Project->C/C++->Code Generation->Runtime Library选项,确保EXE工程和Lib工程都选择相同模式,例如/MDD。如果更改后仍有错误,可能涉及到库文件的冲突。

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
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值