Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

fatal error LNK1169: one or more multiply defined symbols found

1,431 views
Skip to first unread message

Ruben Collado Hernandez

unread,
Nov 26, 1999, 3:00:00 AM11/26/99
to
I'm going crazy...

    I have a big problem with my program in VC++ 6.0. Last wednesday the program runs perfectly, and the next morning this message appeared, within more code:

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)
Bin files/Control.exe : fatal error LNK1169: one or more multiply defined symbols found
Error executing link.exe.

If you can help me out I'll apreciate it.

Thanks.
--
Rubén Collado Hernández
Universidad Politécnica de Madrid
c/ Ronda de Valencia, 3
28012 Madrid - Spain
Tel: +34 91 336 68 78
 

Martin Nolte [MS]

unread,
Nov 26, 1999, 3:00:00 AM11/26/99
to
Hi Ruben,
thatthere's a Knowledgebase Article
PRB: LNK2005 Errors When Link C Run-Time Libs Before MFC Libs
ID: Q148652
Hope this helps !
 
Best Regards,
 
Martin Nolte
Dev Support CE
Microsoft GmbH
 
PRB: LNK2005 Errors When Link C Run-Time Libs Before MFC Libs
ID: Q148652
 
 
 
--------------------------------------------------------------------------------
The information in this article applies to:
 
Microsoft Visual C++, 32-bit Editions, versions 4.0, 4.1, 5.0, 6.0
 
--------------------------------------------------------------------------------
 

SYMPTOMS
When the C Run-Time (CRT) library and MFC libraries are linked in the wrong order, LNK2005 errors like the following may occur:
 
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(dbgnew.obj)
nafxcwd.lib(afxmem.obj) : error LNK2005:
"void * __cdecl operator new(unsigned int,int,char const *,int)"
(??2@YAPAXIHPBDH@Z) already defined in LIBCMTD.lib(dbgnew.obj)
mfcs40d.lib(dllmodul.obj): error LNK2005: _DllMain@12 already defined in
MSVCRTD.LIB (dllmain.obj)
mfcs42d.lib(dllmodul.obj): error LNK2005: _DllMain@12 already defined in
msvcrtd.lib(dllmain.obj)
 
 
 
CAUSE
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.
 
For additional information on weak externals, please see the following article in the Microsoft Knowledge Base:
 
Q72651 "Weak External" Records: Description, Use, and Errors
 
 
 
RESOLUTION
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.
 
Solution One - Force Linker to Link Libraries in Correct Order
Open the Project Settings dialog box by clicking Settings on the Build menu.
 

in the Settings For view, select (highlight) the project configuration that's getting the link errors.
 

Click the Link tab.
 

Select INPUT in the Category combo box.
 

In the Libraries to Ignore edit box, insert the library names (for example, Nafxcwd.lib Libcmtd.lib)
 
NOTE: The linker command line equivalent in /NOD:<library name>
 

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).
 

Solution Two - Find the Problem Module and Correct It
Perform the following steps to see the current library link order:
 

Open the Project Settings dialog box by clicking Settings on the Build menu.
 

In the Settings For view, Select (highlight) the project configuration that's getting the link errors .
 

Click the Link tab.
 

Type the following in the Project Options dialog box:
/verbose:lib
 
 
 
Rebuild your project. The libraries will now be listed in the output window during the linking process.
 
 
 
 
 
STATUS
This behavior is by design.
 
 
 
MORE INFORMATION
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 <Afx.h>) or indirectly (#include <Stdafx.h>). The Afx.h include file forces the correct order of the libraries, by using the #pragma comment (lib,"<libname>") 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 file://!_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.
 
 
 

Keywords          : kberrmsg kbGenInfo kbVC kbVC400 kbVC410 kbVC500 kbVC600
Version           : WINNT:4.0,4.1,5.0,6.0;
Platform          : NT WINDOWS
Issue type        : kbprb
 
Last Reviewed: July 9, 1999
 

--------------------------------------------------------------------------------
Send feedback to MSDN.Look here for MSDN Online resources.

 

Ruben Collado Hernandez

unread,
Nov 29, 1999, 3:00:00 AM11/29/99
to
You are GOD.

THANKS
THANKS
THANKS

    My problem was succesfully resolved. I was getting crazy... during five days.

    I have another problem, I need to link a library as static in Visual Studio 6.0 but i don't know how to do it. Could you help me ???

    Thanks you again.
    Best regards. I'll apreciate it.
 
 

"Martin Nolte [MS]" wrote:

Hi Ruben,thatthere's a Knowledgebase ArticlePRB: LNK2005 Errors When Link C Run-Time Libs Before MFC Libs
ID: Q148652
Hope this helps ! Best Regards, Martin NolteDev Support CEMicrosoft GmbH PRB: LNK2005 Errors When Link C Run-Time Libs Before MFC Libs

--

Jose Felix Hernandez

unread,
Dec 3, 1999, 3:00:00 AM12/3/99
to
"Martin Nolte [MS]" wrote:
Hi Ruben, To build the static library:1. Build a static library using App Wizard "Win 32 Static Link Library"    the settings of a static link library can be found in the MSDN article.     Overview: Creating a Static Library. To link the static library to your exe choose one of the following ways:
    Thank you for your help, but this is not exactly what i wanted to do.

    I have a library (both .lib and .dll), and i have to link that library statically to my program (because i have to send the program to people without that .dll), but i don't know how to do it.

dave

unread,
Dec 5, 1999, 3:00:00 AM12/5/99
to
On the "Project Settings" "Link" tab Category: Input enter the name of your lib file in "Object/library modules". Note that this field is "space separated".
Jose Felix Hernandez <jhe...@maxwell.fais.upm.es> wrote in message news:38478C25...@maxwell.fais.upm.es...
"Martin Nolte [MS]" wrote:
Hi Ruben, To build the static library:1. Build a static library using App Wizard "Win 32 Static Link Library"    the settings of a static link library can be found in the MSDN article.     Overview: Creating a Static Library. To link the static library to your exe choose one of the following ways:
    Thank you for your help, but this is not exactly what i wanted to do.

    I have a library (both .lib and .dll), and i have to link that library statically to my program (because i have to send the program to people without that .dll), but i don't know how to do it.

Jose Felix Hernandez

unread,
Dec 10, 1999, 3:00:00 AM12/10/99
to dave
 
    Hello,

    I have done it, but when i try to run the program on the other computer the next message appears "no file mil.dll...", i want to link the library mil.lib statically to the project.

    Thank you.
    Best regards.

dave wrote:

 On the "Project Settings" "Link" tab Category: Input enter the name of your lib file in "Object/library modules". Note that this field is "space separated".

Jose Felix Hernandez <jhe...@maxwell.fais.upm.es> wrote in message news:38478C25...@maxwell.fais.upm.es..."Martin Nolte [MS]" wrote:
Hi Ruben, To build the static library:1. Build a static library using App Wizard "Win 32 Static Link Library"    the settings of a static link library can be found in the MSDN article.     Overview: Creating a Static Library. To link the static library to your exe choose one of the following ways:
    Thank you for your help, but this is not exactly what i wanted to do.

    I have a library (both .lib and .dll), and i have to link that library statically to my program (because i have to send the program to people without that .dll), but i don't know how to do it.

Jose Felix Hernandez

unread,
Dec 28, 1999, 3:00:00 AM12/28/99
to
 

Jose Felix Hernandez wrote:

 
    Hello,

    Thank you.
    Best regards.

dave wrote:

    I have a library (both .lib and .dll), and i have to link that library statically to my program (because i have to send the program to people without that .dll), but i don't know how to do it.

--
Jose F. Hernandez Barrio

Universidad Politécnica de Madrid
c/ Ronda de Valencia, 3
28012 Madrid - Spain

Neil Gilmore

unread,
Dec 28, 1999, 3:00:00 AM12/28/99
to
It sounds as if you have linked mil.lib statically, but that mil.lib is an
export library. That means that mil.lib just contains references into
mil.dll. Linking (statically) with mil.lib just tells the program that it
needs mil.dll to run. You would still have to send the file mil.dll to
anyone who wants to run the program.

If I'm mistaking the problem, I sorry.

Neil Gilmore
ra...@raito.com

0 new messages