IBM Support

Error LNK2005: "void * __cdecl operator new(unsigned int)" already defined

Troubleshooting


Problem

This technote explains why the error might occur when IBM® Rational® Test RealTime™ instruments a Microsoft® Foundation Class (MFC) application. This application uses dynamic link libraries (DLLs) of the Application Framework Extensions (AFX) .

Symptom

During the instrumentation of an MFC application with AFX DLLs the following error occurs at link time.

The full error message is as follows:

error LNK2005: "void * __cdecl operator new(unsigned int)" already defined

Cause

The Target Deployment Port contains a redefinition of the two C++ functions new and delete. As a consequence the Target Deplyment Port can now detect memory leaks.

By default the Target Deployment Port on Windows tries to link the application statically. This is not possible with applications that use MFC classes and the AFX DLLs, because it results in a double definition of the new operator.

Resolving The Problem

Modify the settings for the runtime analysis node or the component testing for C++ node. Add the following flags:

Configuration Settings > Build > Compiler > Preprocessor Options: -D_AFXDLL -MD

Configuration Settings > Build > Linker > Link Flags: /nodefaultlib:msvcrt




[{"Product":{"code":"SSSHUF","label":"Rational Test RealTime"},"Business Unit":{"code":"BU053","label":"Cloud & Data Platform"},"Component":"--","Platform":[{"code":"PF033","label":"Windows"}],"Version":"2003.06.00;2003.06.01;2003.06.12;2003.06.13;2003.06.15;7.0;7.0.0.1;7.0.5","Edition":"","Line of Business":{"code":"LOB45","label":"Automation"}}]

Historical Number

152827401

Document Information

Modified date:
16 June 2018

UID

swg21131990