0518 lnk2005 dllmain LNK1169

编译一个标准DLL,需要使用AFXMESSAGEBOX TRACE之类的函数,看看
修改STDAFX.H
//#include <windows.h>//yq
#include <afxwin.h>//yq

结果:
——————–Configuration: DllOfUse – 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 LIBCMTD.lib(dbgdel.obj)
Debug/DllOfUse.dll : fatal error LNK1169: one or more multiply defined symbols found
Error executing link.exe.

DllOfUse.dll – 4 error(s), 0 warning(s)

匆忙之下,用 /FORCE  搞定,全部变成了 WARNING
Linker Tools Error LNK1169
one or more multiply defined symbols found

The build failed due to multiple definitions of one or more symbols. This error is preceded by error LNK2005.

The /FORCE or /FORCE:MULTIPLE option overrides this error.

回家看看以前的BLOG http://www.yippeesoft.com/blog/p/0202siportpLNK2005.php
注意:下列步骤基于 Visual C++ 6.0 进行。
我用的是
/nologo /dll /incremental:yes /pdb:"Debug/DllOfUse.pdb" /debug /machine:I386 /nodefaultlib:"libc.lib" /nodefaultlib:"libcd.lib" /nodefaultlib:"libcmt.lib" /out:"Debug/DllOfUse.dll" /implib:"Debug/DllOfUse.lib" /pdbtype:sept

加上 5. 在“对象/库模块”框中,插入库名。Nafxcwd.lib

When using MFC libraries, you must make sure they are linked before the CRT library. This can be done by ensuring every file in your project includes ..\\Msdev\\Mfc\\Include\\Afx.h first, either directly (#include &lt;Afx.h&gt;) or indirectly (#include &lt;Stdafx.h&gt;). The Afx.h include file forces the correct order of the libraries, by using the #pragma comment (lib,"&lt;libname&gt;") directive.

If the source file has a .c extension, or the file has a .cpp extension but does not use MFC, you can create and include a small header file (Forcelib.h) at the top of the module. This new header will ensure the correct library search order.

Visual C++ does not contain this header file, but you can easily create this file by performing the following steps:

Open ..\\Msdev\\Mfc\\Include\\Afx.h.

Select line 29 (#ifndef _AFX_NOFORCE_LIBS) through line 204 (#endif //!_AFX_NOFORCE_LIBS).
Copy the selection to the Windows Clipboard.
Create a new text file.
Paste the contents of the Clipboard into this new file.
Save the file as ..\\Msdev\\Mfc\\Include\\Forcelib.h.

历史博文

标签:,
十月 30, 2006 at 10:31 下午 by yippee 1,075 次
Category: Dev
Tags: ,