概述
1、使用场景:
在非MFC程序(使用MFC作为静态连接库)中,添加MFC支持,静态链接MFC库
使用VC6.0编译时,发生如下错误:
--------------------Configuration: ChinaUnionpayDLL - Win32 Debug--------------------
Linking...
nafxcwd.lib(dllmodul.obj) : error LNK2005: _DllMain@12 already defined in LIBCMTD.lib(dllmain.obj)
nafxcwd.lib(afxmem.obj) : error LNK2005: "void * __cdecl operator new(unsigned int)" (??2@YAPAXI@Z) already defined in LIBCMTD.lib(new.obj)
nafxcwd.lib(afxmem.obj) : error LNK2005: "void __cdecl operator delete(void *)" (??3@YAXPAX@Z) already defined in libcpmtd.lib(delop.obj)
nafxcwd.lib(dllmodul.obj) : warning LNK4006: _DllMain@12 already defined in LIBCMTD.lib(dllmain.obj); second definition ignored
nafxcwd.lib(afxmem.obj) : warning LNK4006: "void * __cdecl operator new(unsigned int)" (??2@YAPAXI@Z) already defined in LIBCMTD.lib(new.obj); second definition ignored
nafxcwd.lib(afxmem.obj) : warning LNK4006: "void __cdecl operator delete(void *)" (??3@YAXPAX@Z) already defined in libcpmtd.lib(delop.obj); second definition ignored
Creating library Debug/ChinaUnionpayDLL.lib and object Debug/ChinaUnionpayDLL.exp
Debug/ChinaUnionpayDLL.dll : fatal error LNK1169: one or more multiply defined symbols found
执行 link.exe 时出错.
ChinaUnionpayDLL.dll - 1 error(s), 0 warning(s)
2、问题原因分析:
CRT 库对 new、delete 和 DllMain 函数使用弱外部链接。MFC 库也包含 new、delete 和 DllMain 函数。这些函数要求先链接 MFC 库,然后再链接 CRT 库。
当 C 运行时 (CRT) 库和 Microsoft 基础类 (MFC) 库的链接顺序有误时,可能会出现以下 LNK2005 错误。
3、解决方案:
VC6设置方法如下:
“工程” >> “设置” >> “连接”,选择Debug模式,在分类中选择输入,在 “对象/库模块" 中输入 nafxcwd.lib libcmtd.lib ,然后在 ”忽略库“ 中输入 nafxcwd.lib,libcmtd.lib ,保存后重编译即可。
Release模式下,只需要将lib库后面的d去掉,即和Debug对应的Release输入为: nafxcw.lib libcmt.lib nafxcw.lib,libcmt.lib
如果还是出现以下编译错误:(存在问题才设置此步骤,不然不需要设置)
>nafxcwd.lib(dllmodul.obj) : error LNK2005: _DllMain@12 已经在 CTXGina.obj 中定义
则可在“工程” >> “设置” >> “C/C++” 中去掉 _USRDLL 预处理宏。Debug和Release都需要设置,方法相同。
最后
以上就是标致毛衣为你收集整理的error LNK2005: _DllMain@12 already defined in LIBCMTD.lib(dllmain.obj) 解决方案的全部内容,希望文章能够帮你解决error LNK2005: _DllMain@12 already defined in LIBCMTD.lib(dllmain.obj) 解决方案所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复