When the C Run-Time (CRT) library and Microsoft Foundation Class (MFC) libraries are linked in the wrong order, you may receive one of the following LNK2005 errors:
nafxcwd.lib(afxmem.obj) : error LNK2005:
"void * __cdecl operator new(unsigned int)"(??2@YAPAXI@Z) already
defined in LIBCMTD.lib(new.obj)
"void * __cdecl operator new(unsigned int)"(??2@YAPAXI@Z) already
defined in LIBCMTD.lib(new.obj)
Note The following steps are based on Visual C++ 6.0.
Solution One: Force Linker to Link Libraries in Correct Order
- On the Project menu, click Settings.
- In the Settings For view of the Project Settings dialog box, click to select the project configuration that is getting the link errors.
- On the Link tab, click to select Input in the Category combo box.
- In the Ignore libraries 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 box, insert the library names. You must make sure that these are listed in order and as the first two libraries in the line (for example, Nafxcwd.lib Libcmtd.lib).
Solution Two: Locate and Correct the Problem Module
To view the current library link order, follow these steps:- On the Project menu, click Settings.
- In the Settings For view of the Project Settings dialog box, click to select the project configuration that is getting the link errors.
- On the Link tab, type /verbose:lib in the Project Options box.
- Rebuild your project. The libraries will be listed in the output window during the linking process.
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 makes sure that thelibrary search order is correct.
Visual C++ does not contain this header file. To create this file, follow these steps:
- Open Msdev\Mfc\Include\Afx.h.
- Select the lines between #ifndef _AFX_NOFORCE_LIBS and #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.

没有评论:
发表评论