BUG: You receive a linker error message when you build an Itanium architecture-based application (833981)



The information in this article applies to:

  • Microsoft Windows Server 2003, Enterprise Edition for Itanium-based Systems
  • Microsoft Windows Server 2003, Datacenter Edition for Itanium-based Systems
  • Microsoft Windows XP 64-Bit Edition Version 2003
  • Microsoft Windows XP 64-Bit Edition Version 2002

SYMPTOMS

When you build an Itanium architecture-based application that uses Microsoft Foundation Classes (MFC) headers, you may receive the following linker error message:
libcmtd.lib(dbgnew.obj) : error LNK2005: "void * __cdecl operator new(unsigned __int64,int,char const *,int)" (??2@YAPEAX_KHPEBDH@Z) already defined in nafxcwd.lib(afxmem.obj)

libcmtd.lib(dbgnew.obj) : error LNK2005: "[Entry] void * __cdecl operator new(unsigned __int64,int,char const *,int)" (.??2@YAPEAX_KHPEBDH@Z) already defined in nafxcwd.lib(afxmem.obj)

Q833981.exe : fatal error LNK1169: one or more multiply defined symbols found
When you use the UndName tool on the decorated name ??2@YAPEAX_KHPEBDH@Z, you receive the following output: Microsoft (R) C++ Name Undecorator
Copyright (C) Microsoft Corporation 1981-2001. All rights reserved.
Undecoration of :- "??2@YAPEAX_KHPEBDH@Z" is :- "void * __ptr64 __cdecl operator new(unsigned __int64,int,char const * __ptr64,int)"

WORKAROUND

To work around this problem, define the operators in your application.
#ifdef _DEBUG

void* operator new[](size_t nSize, LPCSTR lpszFileName, int nLine) {
return ::operator new[](nSize, _NORMAL_BLOCK, lpszFileName, nLine); }

void* operator new[](size_t nSize, int nType, LPCSTR lpszFileName, int nLine) {
return ::operator new(nSize, nType, lpszFileName, nLine);
}

#endif

STATUS

Microsoft has confirmed that this is a problem in the Microsoft products that are listed in the "Applies to" section.

MORE INFORMATION

Steps to reproduce the problem

  1. Install the Microsoft Platform Software Development Kit (SDK) to obtain the 64-bit compilers. For more information about the Microsoft Platform SDK, visit the following Microsoft Web site:
  2. Use the following code to create a new .cpp file. Name the file Q833981.cpp.
    #include <afx.h>
    #include <fstream.h>
    
    int main()
    {
        int * p = new int;
        int *p1 = new int[5];
        ifstream ifs;
    }
  3. Set a 64-bit build environment by using the Set Environment Variable Tool (Setenv.bat). The Set Environment Variable Tool is included with the Microsoft Platform SDK. For example, at a command prompt, run the following command for your build environment:
    • Windows Server 2003 64-bit build environment

      setenv.bat /SRV64 /DEBUG

    • Windows XP 64-bit build environment

      setenv.bat /XP64 /DEBUG

  4. Compile the Q833981.cpp file by using Microsoft C/C++ Complier (Cl.exe). This tool is located in the following folder:

    Drive\Program Files\Microsoft SDK\Bin\Win64

    To compile the file, run the following command at a command prompt:

    cl /MTd Q833981.cpp


Modification Type:MinorLast Reviewed:7/5/2005
Keywords:kbBug kbCompiler kbSDK kbcode kberrmsg KB833981 kbAudDeveloper