如果出现这种错误:“uafxcwd.lib(dllmodul.obj) : error LNK2005: _DllMain@12 already defined in main.obj ”或者“mfcs42ud.lib(dllmodul.obj) : error LNK2005: _DllMain@12 already defined in main.obj ”,那么“See if you have _AFXDLL and _USRDLL in the preprocessor definitions. Try removing one of them”。具体位置:IDE中 菜单Project / Setting / C/C++ / preprocessor definition 。
Project / Setting / C/C++ / 代码生成---->>运行时库---->>多线程调试 DLL (/MDd)
资深员工说加入以下代码:
#include "stdafx.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define new DEBUG_NEW
/////////////////////////////////////////////////////////////////////////////
// global data
// The following symbol used to force inclusion of this module for _USRDLL
#ifdef _X86_
extern "C" { int _afxForceUSRDLL; }
#else
extern "C" { int __afxForceUSRDLL; }
#endif
另外,极有可能是加了#include <afx.h>
后记:
来此取经的有人说:
http://hi.baidu.com/ollyestn/blog/item/c9baf4df832042e676c638a8.html
今天编译又碰到这个DllMain已经在xxx中被定义的问题,搜了一下,情况还很多,不过主要还是预定义的问题,我的预 定义宏如下:
_DEBUG;_WIN32_WCE=$(CEVER);UNDER_CE;$(PLATFORMDEFINES);WINCE;DEBUG;_WINDOWS;_USRDLL;$(ARCHFAM);$(_ARCHFAM_);_UNICODE;UNICODE;
网上有人说是:“See if you have _AFXDLL and _USRDLL in the preprocessor definitions. Try removing one of them”。但是我的定义里面只有一个 _USRDLL 而没有 _AFXDLL,但是在stdafx.h中代码中包括了包含了<afxwin.h>。
现在只要去掉_USRDLL ,再编译,OK。
简单的记下来,仅为下次碰到该问题时,不再迷惑。
----不知道是否真切
本文介绍了解决链接器错误_Lnk2005的具体步骤,特别是针对_DllMain函数重复定义的问题。建议检查预处理器定义是否存在冲突,并提供了一段示例代码帮助解决此类问题。
2410

被折叠的 条评论
为什么被折叠?



