INFO: _DEBUG Must Be Defined When Linking to Debug Libraries

This article was previously published under Q85514
This article has been archived. It is offered "as is" and will no longer be updated.
SUMMARY
To link an application with the debugging version of the MicrosoftFoundation Class (MFC) libraries, the source code must define the _DEBUGmacro at compile time. Specify the name of the appropriate MFC library onthe LINK command line before the name of the appropriate C/C++ Run-timeLibrary.
MORE INFORMATION
The debugging versions of the MFC libraries provide additional debugginginformation in functions that the C/C++ run-time libraries normally provide(such as "new" and "delete"). An attempt to link code compiled whenthe_DEBUG macro is not defined with the debugging libraries may fail andLINK may generate errors similar to the following:
   C:\...\MFC\lib\safxcwd.lib(memory.cpp) : error L2025: public:      static void __near* __near __cdecl      CObject::operator new(unsigned int) : symbol defined      more than once					
   C:\...\MFC\lib\safxcwd.lib(memory.cpp) : error L2025: public:      static void __near __cdecl      CObject::operator delete(void __near*) : symbol defined      more than once					
When compiling from the command line, use the /D compiler option tospecify the _DEBUG macro. For example, in Microsoft C/C++ version 7.0for MS-DOS and Windows or in Visual C++ version 1.0 or 1.5 for Windows,the command line might look like the following:
   cl /AS /D_DEBUG test.cpp safxcwd.lib				
In Visual C++ 32-bit edition version 1.0, the command line might looklike the following:
   cl /D_DEBUG /D_X86_ test.cpp nafxcwd				
When you compile code that uses the Microsoft Foundation Classes inProgrammer's WorkBench (PWB), select the Use MFC Libraries option. (Todo so, choose Language Options from the Options menu, then chooseCompiler Options, choose Additional Compiler Options, and select MFCLibraries. Then choose OK.) PWB automatically inserts the /D_DEBUGoption when it compiles the debugging version of your application. ThePWB-generated LINK command specifies the appropriate MicrosoftFoundation Classes library and the appropriate C/C++ Run-time Libraryin the correct order.

When you compile code that uses the Microsoft Foundation Classes inVisual Workbench (VWB) in Visual C++ 1.0 or 1.5 for Windows, or VisualC++, 32-bit edition, version 1.0, select the Use MFC Libraries option. (Todo so, choose Project from the Options menu, then select Use MicrosoftFoundation Classes and choose OK.) VWB automatically inserts the /D_DEBUGoption when is compiles the debugging version of your application. The VWB-generated LINK command specifies the appropriate Microsoft FoundationClasses library and the appropriate C/C++ run-time library in thecorrect order.

In Visual C++, 32-bit Edition, version 2.0 and later, internal makefilesautomatically include a /D_DEBUG option on the build line debug targets.Therefore, removing /D_DEBUG from the preprocessor command line optionsdoes not cause an error.
Properties

Article ID: 85514 - Last Review: 10/08/2013 04:59:29 - Revision: 3.1

  • Microsoft Foundation Class Library 4.2
  • kbnosurvey kbarchive kbbug kbdebug kbinfo KB85514
Feedback