您的位置:首页 > 大数据 > 人工智能

error LNK2005: _DllMain@12 already defined in LIBCMTD.lib(dllmain.obj) 解决方案

2016-01-26 11:36 507 查看
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都需要设置,方法相同。

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: