Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

error LNK2005: new and delete already defined in LIBCMTD.lib(new.obj)

The CRT libraries use weak external linkage for the new, delete, 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. http://support.microsoft.com/kb/148652

Solution based on VS2005 (Replace Nafxcwd.lib with Uafxcwd.lib for ~VS2013)

go to project>properties>configuration properties>linker>input

add to "Additional dependency" -> Nafxcwd.lib Libcmtd.lib

add to "ignore specific library" -> Nafxcwd.lib;Libcmtd.lib

order of libraries is important( Nafxcwd.lib;Libcmtd.lib).


One thing to try is to make sure you have:

#include "stdafx.h"

as the first line in your .cpp files. I'm sure that's not the answer in all cases, but it made the identical error go away in my case.


I meet this problem in a MFC solution of Visual Studio 2010, while changing Use MFC in a Shared DLL into Use MFC in a Static Library in Project -> Properties -> Configuration Properties -> General.

I solve the problem by the following ways, please locate Project -> Properties -> Configuration Properties -> Linker -> Input at first.

In Debug mode:

  • Add uafxcwd.lib;Libcmtd.lib in Additional Dependencies.
  • Add uafxcwd.lib;Libcmtd.lib in Ignore Specific Default Libraries.

In Release mode:

  • Add uafxcw.lib;Libcmt.lib in Additional Dependencies.
  • Add uafxcw.lib;Libcmt.lib in Ignore Specific Default Libraries.

Notice:

  1. Don't miss the ; between the two .lib files.
  2. A suffix -d must be added in the files in Debug mode.

be sure that you have #include <afx.h> in "stdafx.h" BEFORE other includes like #include <string>


in config linker input

  • In additional dependicies put uafxcw.lib;LIBCMT.lib
  • In Ignore specific put put uafxcw.lib;LIBCMT.lib

Make sure the C++ runtime library that you are linking with is the same on your static library as well as your executable. Check your project properties C/C++->Code generation->runtime library settings.


Typo. One stupid way you got that is instead of include the header, you inlucde the cpp. e.g.

#include <myclass.cpp> //should be #include <myClass.h>