How to: Build an MFC Application with Debug Information for Selected Modules
This topic applies to:
Edition |
Visual Basic |
C# |
F# |
C++ |
Web Developer |
---|---|---|---|---|---|
Express |
Native only |
||||
Pro, Premium, and Ultimate |
Native only |
Note
The dialog boxes and menu commands you see might differ from those described in Help depending on your active settings or edition. To change your settings, choose Import and Export Settings on the Tools menu. For more information, see Working with Settings.
Building selected modules with the MFC debug libraries enables you to use stepping and the other debug facilities in those modules. This procedure makes use of both the Debug and Release modes of the Visual C++ makefile, thus necessitating the changes described in the following steps (and also making a "rebuild all" necessary when a full Release build is required).
To build an MFC application with debug information for selected modules
In Solution Explorer, select the project.
From the View menu, select Property Pages.
First, you will create a new project configuration.
In the <Project> Property Pages dialog box, click the Configuration Manager button.
In the Configuration Manager dialog box, locate your project in the grid. In the Configuration column, select <New...>.
In the New Project Configuration dialog box, type a name for your new configuration, such as "Partial Debug", in the Project Configuration Name box.
In the Copy Settings from list, choose Release.
Click OK to close the New Project Configurationdialog box.
Close the Configuration Manager dialog box.
Now, you will set options for the entire project.
In the Property Pages dialog box, under the Configuration Properties folder, select the General category.
In the project settings grid, expand Project Defaults (if necessary).
Under Project Defaults, find Use of MFC. The current setting appears in the right column of the grid. Click on the current setting and change it to Use MFC in a Static Library.
In the left pane of the Properties Pages dialog box, open the C/C++ folder and select Preprocessor. In the properties grid, find Preprocessor Definitions and replace "NDEBUG" with "_DEBUG".
In the left pane of the Properties Pages dialog box, open the Linker folder and select the Input Category. In the properties grid, find Additional Dependencies. In the Additional Dependencies setting, type "NAFXCWD.LIB" and "LIBCMT."
Click OK to save the new build options and close the Property Pages dialog box.
From the Build menu, select Rebuild. This removes all debug information from your modules but does not affect the MFC library.
Now you must add debug information back to selected modules in your application. Remember that you can set breakpoints and perform other debugger functions only in modules you have compiled with debug information. For each project file in which you want to include debug information, carry out the following steps:
In Solution Explorer, open the Source Files folder located under your project.
Select the file you want to set debug information for.
From the View menu, select Property Pages.
In the Property Pages dialog box, under the Configuration Settings folder, open the C/C++ folder then select the General category.
In the properties grid, find Debug Information Format.
Click the Debug Information Format settings and select the desired option (usually /ZI) for debug information.
If you are using an application wizard-generated application or have precompiled headers, you have to turn off the precompiled headers or recompile them before compiling the other modules. Otherwise, you will receive warning C4650 and error message C2855. You can turn off precompiled headers by changing the Create/Use Precompiled Headers setting in the <Project> Properties dialog box (Configuration Properties folder, C/C++ subfolder, Precompiled Headers category).
From the Build menu, select Build to rebuild project files that are out of date.
As an alternative to the technique described in this topic, you can use an external makefile to define individual options for each file. In that case, to link with the MFC debug libraries, you must define the _DEBUG flag for each module. If you want to use MFC release libraries, you must define NDEBUG. For more information on writing external makefiles, see the NMAKE Reference.
See Also
Tasks
How to: Reduce the Size of an MFC Debug Build