FIX: Global Overloaded Delete Operator Causes LNK2005 (140440)



The information in this article applies to:

  • Microsoft Visual C++ 4.0

This article was previously published under Q140440

SYMPTOMS

When globally overloading operator delete, the linker may generate the following errors when building in the debug mode and using the static C run-time libraries:
error LNK2005: "void __cdecl operator delete(void *)"(??3@YAXPAX@Z)
already defined in file.obj
fatal error LNK1169: one or more multiply defined symbols found

RESOLUTION

The problem only appears with the static C run-time libraries for the debug mode; it does not occur when using the release mode. Also at this time, the problem is noted to occur only when an iostream object is linked in. For example, in the code fragment listed in the "Steps to Reproduce Problem" section of this article, if you change the statement to output to "cout" into a comment inside main(), the problem does not occur.

To work around this problem:

  1. Use the DLL version of the C Run-Time library.
  2. Bring up the Project Settings dialog box. On the Build menu, click Settings. Click the Link tab, and select the Customize category. Select the Force File output option. This forces the linker to generate the executable regardless of the error.

STATUS

Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. This bug was corrected in Visual C++ 4.1.

MORE INFORMATION

Steps to Reproduce Problem

Build the following program as a console application using the debug mode.
// test.cpp

#include <iostream.h>
#include <malloc.h>

void operator delete (void *p)
{
   free (p);
}

void main()
{
   cout << "main" << endl;
}
				

Modification Type:MajorLast Reviewed:10/16/2002
Keywords:kbBug kbCRT kbVC410fix KB140440