Microsoft KB Archive/184235

= You receive LNK2005 errors when you compile an ATL executable (.exe) project in Visual C++ =

Article ID: 184235

Article Last Modified on 6/6/2005

-

APPLIES TO


 * Microsoft Visual C++ 5.0 Enterprise Edition
 * Microsoft Visual C++ 6.0 Enterprise Edition
 * Microsoft Visual C++ 5.0 Professional Edition
 * Microsoft Visual C++ 6.0 Professional Edition
 * Microsoft Visual C++ 6.0 Standard Edition

-



This article was previously published under Q184235



SYMPTOMS
When you compile an Active Template Library (ATL) executable (.exe) project in Developer Studio, the _ATL_MIN_CRT preprocessor symbol allows you to use some standard C library functions without having to link in the C run-time library (CRT) startup code. If _ATL_MIN_CRT is defined when you build an ATL executable with Microsoft Foundation Classes (MFC) support, the linker returns the following linker errors:

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

nafxcw.lib(afxmem.obj) : error LNK2005: "void __cdecl operator delete(void *)" (??3@YAXPAX@Z) already defined in StdAfx.obj



CAUSE
Some C run-time library functions require that you provide the CRT startup code. Because both the C run-time and MFC libraries contain definitions for the new and delete operators, there is a conflict for the linker.



RESOLUTION
Remove the _ATL_MIN_CRT preprocessor definition and rebuild the project. To do this, click Settings on the Project menu. On the C/C++ tab, select the Preprocessor category, and remove the _ATL_MIN_CRT definition.



STATUS
This behavior is by design.



Steps to Reproduce Behavior
 Create an ATL COM AppWizard application. On the File menu, click New, and select ATL COM AppWizard as the project type. Use the information in the following Microsoft Knowledge Base article to add MFC support to your ATL project:

173974 HOWTO: Add MFC Support to an ATL Project

 Add _ATL_MIN_CRT to your preprocessor definitions using the preprocessor settings described in the RESOLUTION section of this article. On the Build menu, click Set Active Configuration, and choose the Win32 Release MinSize configuration. Build the project. You should see both LNK2005 errors in the build output window.</li></ol>

<div class="references_section">