You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
l3lib/devel/trash/linkerError_libs_debug_new....

168 lines
7.8 KiB
HTML

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html dir="ltr" lang="en">
<head>
<title>CodeGuru Forums - link-error LNK2005</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<meta name="keywords" content="Visual C++,C++,CodeGuru,Code,Guru,.NET,Microsoft,C#,Visual Basic,Coding,forum,bbs,discussion" />
<meta name="description" content="Hard hitting articles, dicussions, resources, and more all focusing for real developers in the real world." />
<link rel="stylesheet" href="http://www.codeguru.com/forum/archive/archive.css" />
</head>
<body>
<div class="pagebody">
<div id="navbar"><a href="./">CodeGuru Forums</a> &gt; <a href="f-41.html">Visual C++ & C++ Programming</a> &gt; <a href="f-7.html">Visual C++ Programming</a> &gt; link-error LNK2005</div>
<hr />
<div class="pda"><a href="?pda=1">PDA</a></div>
<p class="largefont"><span style="color:red">Click Here To View Forum --></span> : <a href="http://www.codeguru.com/forum/showthread.php?t=102337">link-error LNK2005</a></p>
<hr />
<div class="post"><div class="posttop"><div class="username"></div><div class="date">08-01-2000, 07:12 AM</div></div><div class="posttext">Hi,<br />
<br />
my MFC-Project uses the following settings:<br />
<br />
c++:<br />
/nologo /MTd /W3 /Gm /GX /ZI /Od /I &quot;.\include&quot; /D &quot;_DEBUG&quot; /D &quot;WIN32&quot; /D &quot;_WINDOWS&quot; /D &quot;_MBCS&quot; /D &quot;LOGFILE&quot; /FR&quot;Debug/&quot; /Fo&quot;Debug/&quot; /Fd&quot;Debug/&quot; /FD /GZ /c <br />
<br />
linker:<br />
ws2_32.lib /nologo /subsystem:windows /incremental:yes /pdb:&quot;Debug/udp_test.pdb&quot; /debug /machine:I386 /out:&quot;Debug/udp_test.exe&quot; /pdbtype:sept<br />
<br />
and throws the following error-message on linking:<br />
<br />
nafxcwd.lib(afxmem.obj) : error LNK2005: &quot;void * __cdecl operator new(unsigned int)&quot; (??2@YAPAXI@Z) bereits in (already on) LIBCMTD.lib(new.obj) definiert (defined)<br />
nafxcwd.lib(afxmem.obj) : error LNK2005: &quot;void __cdecl operator delete(void *)&quot; (??3@YAXPAX@Z) bereits in (already on) libcpmtd.lib(delop.obj) definiert (defined)<br />
<br />
I use the german-version 6.0 Enterprise with SP 3 on WinNT 4 with SP 5.<br />
<br />
Does anybody knows about this prob and how to solve it?<br />
<br />
Thanks,<br />
<br />
Thomas</div></div><hr />
<div class="post"><div class="posttop"><div class="username">jrwcode</div><div class="date">08-01-2000, 08:34 AM</div></div><div class="posttext">Hi<br />
What you might want to try and do is go into the project settings and goto the C/C++ tag and then goto the Code Generation Category. There you will find the Use run-time library. You will want to make sure that all you librarys are either all single-threaded or multi-threaded. Have a play around with these settings. That might do the trick.<br />
<br />
Hope that helped.<br />
<br />
J</div></div><hr />
<div class="post"><div class="posttop"><div class="username">m_srinivas</div><div class="date">08-01-2000, 09:50 AM</div></div><div class="posttext">SYMPTOMS<br />
When the C Run-Time (CRT) library and MFC libraries are linked in the wrong order, LNK2005 errors like the following may occur: <br />
<br />
nafxcwd.lib(afxmem.obj) : error LNK2005:<br />
&quot;void * __cdecl operator new(unsigned int)&quot;(??2@YAPAXI@Z) already<br />
defined in LIBCMTD.lib(new.obj) <br />
nafxcwd.lib(afxmem.obj) : error LNK2005:<br />
&quot;void __cdecl operator delete(void *)&quot;(??3@YAXPAX@Z) already defined<br />
in LIBCMTD.lib(dbgnew.obj) <br />
nafxcwd.lib(afxmem.obj) : error LNK2005:<br />
&quot;void * __cdecl operator new(unsigned int,int,char const *,int)&quot;<br />
(??2@YAPAXIHPBDH@Z) already defined in LIBCMTD.lib(dbgnew.obj) <br />
mfcs40d.lib(dllmodul.obj): error LNK2005: _DllMain@12 already defined in<br />
MSVCRTD.LIB (dllmain.obj) <br />
mfcs42d.lib(dllmodul.obj): error LNK2005: _DllMain@12 already defined in<br />
msvcrtd.lib(dllmain.obj) <br />
<br />
<br />
<br />
CAUSE<br />
The CRT libraries use weak external linkage for the new, delete, and DllMain functions. The MFC libraries also contain new, delete, and DllMain functions, requiring MFC to be linked before the CRT libraries. <br />
<br />
For additional information on weak externals, please see the following article in the Microsoft Knowledge Base: <br />
<br />
Q72651 &quot;Weak External&quot; Records: Description, Use, and Errors <br />
<br />
<br />
<br />
RESOLUTION<br />
There are two ways to resolve this problem. The first solution involves forcing the linker to link the libraries in the correct order. The second solution allows you to find the module that's causing the problem and correct it. <br />
<br />
Solution One - Force Linker to Link Libraries in Correct Order<br />
Open the Project Settings dialog box by clicking Settings on the Build menu. <br />
<br />
<br />
in the Settings For view, select (highlight) the project configuration that's getting the link errors. <br />
<br />
<br />
Click the Link tab. <br />
<br />
<br />
Select INPUT in the Category combo box. <br />
<br />
<br />
In the Libraries to Ignore edit box, insert the library names (for example, Nafxcwd.lib Libcmtd.lib) <br />
<br />
NOTE: The linker command line equivalent in /NOD:&amp;lt;library name&amp;gt; <br />
<br />
<br />
In the Object/library Modules edit box, insert the library names. You must ensure that these are listed in order and as the first two libraries in the line (for example, Nafxcwd.lib Libcmtd.lib). <br />
<br />
<br />
Solution Two - Find the Problem Module and Correct It<br />
Perform the following steps to see the current library link order: <br />
<br />
<br />
Open the Project Settings dialog box by clicking Settings on the Build menu. <br />
<br />
<br />
In the Settings For view, Select (highlight) the project configuration that's getting the link errors . <br />
<br />
<br />
Click the Link tab. <br />
<br />
<br />
Type the following in the Project Options dialog box: <br />
/verbose:lib <br />
<br />
<br />
<br />
Rebuild your project. The libraries will now be listed in the output window during the linking process.<br />
<br />
<br />
<br />
<br />
<br />
STATUS<br />
This behavior is by design. <br />
<br />
<br />
<br />
MORE INFORMATION<br />
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 &amp;lt;Afx.h&amp;gt;) or indirectly (#include &amp;lt;Stdafx.h&amp;gt;). The Afx.h include file forces the correct order of the libraries, by using the #pragma comment (lib,&quot;&amp;lt;libname&amp;gt;&quot;) directive. <br />
<br />
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. <br />
<br />
Visual C++ does not contain this header file, but you can easily create this file by performing the following steps: <br />
<br />
<br />
<br />
Open ..\Msdev\Mfc\Include\Afx.h. <br />
<br />
<br />
Select line 29 (#ifndef _AFX_NOFORCE_LIBS) through line 204 (#endif //!_AFX_NOFORCE_LIBS). <br />
<br />
<br />
Copy the selection to the Windows Clipboard. <br />
<br />
<br />
Create a new text file. <br />
<br />
<br />
Paste the contents of the Clipboard into this new file. <br />
<br />
<br />
Save the file as ..\Msdev\Mfc\Include\Forcelib.h.<br />
<br />
<br />
<br />
Keywords : kberrmsg kbGenInfo kbVC kbVC400 kbVC410 kbVC500 kbVC600 <br />
Version : WINNT:4.0,4.1,5.0,6.0; <br />
Platform : NT WINDOWS <br />
Issue type : kbprb</div></div><hr />
<div id="copyright"><a href="http://www.codeguru.com/">codeguru.com</a><br />
Copyright 2006 Jupitermedia Corporation All Rights Reserved.</div>
</div>
</body>
</html>