LNK2005 error on C++ app when implementing a replacement new and delete

Mike Nice 20 Reputation points
2025-05-30T15:51:20.56+00:00

In Visual Studio 2019 C++14 I can build a "hello world" program with a custom new and delete.

I'm unable to link a larger program which implements a custom new and delete replacement.

The error is

LNK2005 "void * __cdecl operator new(unsigned int)" (??2@YAPAXI@Z) already defined in nafxcw.lib(afxmem.obj)

I've tried all the suggestions listed at

https://stackoverflow.com/questions/1146338/error-lnk2005-new-and-delete-already-defined-in-libcmtd-libnew-obj

Also trying to understand the verbose Link output.

C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,960 questions
0 comments No comments
{count} votes

Accepted answer
  1. RLWA32 49,301 Reputation points
    2025-05-30T17:25:02.2633333+00:00

    It appears that you are trying to build an MFC application. The MFC framework implements its own custom versions of new and delete. I don't recommend trying to replace the framework's memory management implementation.

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Newest

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.