FIX: Global Overloaded Delete Operator Causes LNK2005

Last reviewed: September 19, 1997
Article ID: Q140440
4.00 WINDOWS NT kbprg kbbuglist kbfixlist

The information in this article applies to:

  • Microsoft Visual C++, 32-bit Edition, version 4.0

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;
}


Additional reference words: 4.00 4.10
KBCategory: kbprg kbbuglist kbfixlist
KBSubcategory: CRTIss vcbuglist400 vcfixlist410
Keywords : CRTIss vcbuglist400 vcfixlist410 kbbuglist kbfixlist kbprg
Version : 4.00
Platform : NT WINDOWS
Solution Type : kbfix


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: September 19, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.