nafxcwd.lib(afxmem.obj) : "void * __cdecl operator new(unsigned int)" already defined in LIBCMT.lib

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

CAUSEThe CRT libraries use weak external linkage for the newdelete, and DllMain functions. The MFC libraries also contain new,delete, and DllMain functions. These functions require the MFC libraries to be linked before the CRT library is linked. 

Solution One: Force Linker to Link Libraries in Correct Order

  1. On the Project menu, click Settings.
  2. In the Settings For view of the Project Settings dialog box, click to select the project configuration that is getting the link errors.
  3. On the Link tab, click to select Input in the Category combo box.
  4. 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>.
  5. 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).
For VS 2010, 
1. Choose the project, right click ,select Properties.
2. In Configuration Properties view, on Linker tab, select Input.
3. Add the libraries to Additional Dependencies (for example, Nafxcwd.lib Libcmtd.lib).
4. Add the libraries toIgnore Specific Default Libraries (for example, Nafxcwd.lib Libcmtd.lib).

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章