调试错误的解决:error LNK2005: "void * __cdecl operator new(unsigned int)" (??2@YAPAXI@Z) 已经在 LIBCMT.lib(ne

本文解决了在链接MFC库和CRT库时遇到的LNK2005重复定义错误,通过调整链接顺序并指定特定库文件,成功解决了编译问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

问题: error LNK2005: “void * __cdecl operator new(unsigned int)” (??2@YAPAXI@Z) 已经在 LIBCMT.lib(new.obj) 中定义。

参考:http://zhanyonhu.blog.163.com/blog/static/16186044201023094754832/

1>uafxcw.lib(afxmem.obj) : error LNK2005: “void * __cdecl operator new(unsigned int)” (??2@YAPAXI@Z) 已经在 LIBCMT.lib(new.obj) 中定义
1>uafxcw.lib(afxmem.obj) : error LNK2005: “void __cdecl operator delete(void *)” (??3@YAXPAX@Z) 已经在 LIBCMT.lib(delete.obj) 中定义
1>uafxcw.lib(afxmem.obj) : error LNK2005: “void * __cdecl operator new[](unsigned int)” (??_U@YAPAXI@Z) 已经在 LIBCMT.lib(new2.obj) 中定义
1>../bin/TLLogger_Unicode_Release.exe : fatal error LNK1169: 找到一个或多个多重定义的符号

原因:

CRT 库对 new、delete 和 DllMain 函数使用弱外部链接。MFC 库也包含 new、delete 和 DllMain 函数。这些函数要求先链接 MFC 库,然后再链接 CRT 库。

当 C 运行时 (CRT) 库和 Microsoft 基础类 (MFC) 库的链接顺序有误时,可能会出现以下 LNK2005 错误。

解决方法:

强制链接器按照正确的顺序链接库!

project->properties->Linker->Ignore Specific Library 添加 uafxcwd.lib Libcmtd.lib

在Additional Dependencied添加uafxcwd.lib Libcmtd.lib

1>Misc.obj : error LNK2001: 无法解析的外部符号 "void __cdecl operator delete(void *,unsigned __int64)" (??3@YAXPEAX_K@Z) 21:13:14:191 1>AiManager.obj : error LNK2001: 无法解析的外部符号 "void __cdecl operator delete(void *,unsigned __int64)" (??3@YAXPEAX_K@Z) 21:13:14:191 1>CBuffManager.obj : error LNK2001: 无法解析的外部符号 "void __cdecl operator delete(void *,unsigned __int64)" (??3@YAXPEAX_K@Z) 21:13:14:191 1>CObject.obj : error LNK2001: 无法解析的外部符号 "void __cdecl operator delete(void *,unsigned __int64)" (??3@YAXPEAX_K@Z) 21:13:14:191 1>dllmain.obj : error LNK2001: 无法解析的外部符号 "void __cdecl operator delete(void *,unsigned __int64)" (??3@YAXPEAX_K@Z) 21:13:14:191 1>Misc.obj : error LNK2001: 无法解析的外部符号 atexit 21:13:14:191 1>ShellCode.obj : error LNK2001: 无法解析的外部符号 atexit 21:13:14:191 1>AiManager.obj : error LNK2001: 无法解析的外部符号 atexit 21:13:14:191 1>CBuffManager.obj : error LNK2001: 无法解析的外部符号 atexit 21:13:14:191 1>CObject.obj : error LNK2001: 无法解析的外部符号 atexit 21:13:14:191 1>dllmain.obj : error LNK2001: 无法解析的外部符号 atexit 21:13:14:191 1>CBuffManager.obj : error LNK2001: 无法解析的外部符号 _fltused 21:13:14:191 1>dllmain.obj : error LNK2001: 无法解析的外部符号 _fltused 21:13:14:203 1>Misc.obj : error LNK2001: 无法解析的外部符号 _fltused 21:13:14:203 1>Vector.obj : error LNK2001: 无法解析的外部符号 _fltused 21:13:14:203 1>dllmain.obj : error LNK2001: 无法解析的外部符号 "void * __cdecl operator new(unsigned __int64)" (??2@YAPEAX_K@Z) 21:13:14:203 1>dllmain.obj : error LNK2001: 无法解析的外部符号 "void * __cdecl operator new[](unsigned __int64)" (??_U@YAPEAX_K@Z) 21:13:14:203 1>ShellCode.obj : error LNK2001: 无法解析的外部符号 "void * __cdecl operator new[](unsigned __int64)" (??_U@YAPEAX_K@Z) 21:13:14:203 1>dllmain.obj : error LNK2001: 无法解析的外部符号 "void __cdecl operator delete[](void *)" (??_V@YAXPEAX@Z) 21:13:14:203 1>ShellCode.obj : error LNK2001: 无法解析的外部符号 "void __cdecl operator delete[](void *)" (??_V@YAXPEAX@Z) 21:13:14:203 1>dllmain.obj : error LNK2001: 无法解析的外部符号 _Init_thread_header 21:13:14:203 1>dllmain.obj : error LNK2001: 无法解析的外部符号 _Init_thread_footer 21:13:14:203 1>dllmain.obj : error LNK2001: 无法解析的外部符号 __imp_GetAsyncKeyState 21:13:14:203 1>dllmain.obj : error LNK2001: 无法解析的外部符号 __imp_GetForegroundWindow 21:13:14:203 1>dllmain.obj : error LNK2001: 无法解析的外部符号 "void __cdecl std::_Xlength_error(char const *)" (?_Xlength_error@std@@YAXPEBD@Z) 21:13:14:203 1>dllmain.obj : error LNK2001: 无法解析的外部符号 __chkstk 21:13:14:203 1>dllmain.obj : error LNK2001: 无法解析的外部符号 _Init_thread_epoch 21:13:14:203 1>dllmain.obj : error LNK2001: 无法解析的外部符号 "__declspec(dllimport) void (__cdecl* std::_Raise_handler)(class stdext::exception const &)" (__imp_?_Raise_handler@std@@3P6AXAEBVexception@stdext@@@ZEA) 21:13:14:203 1>dllmain.obj : error LNK2001: 无法解析的外部符号 "const type_info::`vftable'" (??_7type_info@@6B@) 21:13:14:203 1>dllmain.obj : error LNK2001: 无法解析的外部符号 _tls_index 21:13:14:203 1>D:\WeGameApps\英雄联盟\Game\hid.dll : fatal error LNK1120: 16 个无法解析的外部命令
最新发布
08-08
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值