Link error LNK2005

Link error LNK2005

Was getting this error with some legacy code when converted to VS 2008:

nafxcw.lib(afxmem.obj) : error LNK2005: “void * __cdecl operator new(unsigned int)” (??2@YAPAXI@Z) already defined in LIBCMTD.lib(new.obj)

This article provided a solution.  More  discussion on this issue here.

Overview of C Run-Time and associated options

Based on Visual C++ 6.0:

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

Leave a Reply