When the MFC Application Wizard generates a project, it generates switch settings and files for precompiled headers. You must understand how the make system processes precompiled headers in order to manage your projects effectively.
Note |
Visual C++ .NET has two precompiled header "systems": automatic and manual. Automatic precompiled headers, which are activated by the /Yx compiler switch, store compiler output in a "database" file. Manual precompiled headers are activated by the /Yc and /Yu switch settings and are central to all the MFC Application Wizard–generated projects. |
Precompiled headers represent compiler "snapshots" taken at a particular line of source code. In MFC library programs, the snapshot is generally taken immediately after the following statement:
#include "StdAfx.h"
The file
#include <afxwin.h> #include <afxext.h>
If you're using compound documents,
#include <afxole.h>
And if you're using Automation or ActiveX controls, it contains:
#include <afxdisp.h>
If you're using Internet Explorer 4.0 Common Controls,
#include <afxdtctl.h>
Occasionally, you'll need other header files—for example, the header for template-based collection classes that is accessed by this statement:
#include <afxtempl.h>
The source file
#include "StdAfx.h"
This statement is used to generate the precompiled header file in the project directory. The MFC library headers included by
Figure 3-1: The Visual C++ .NET precompiled header process.
The MFC Application Wizard sets the /Yc and /Yu switches for you, but you can make changes if you need to. It's possible to define compiler switch settings for individual source files. If you select only
Be aware that PCH files are big—10 MB is typical. If you're not careful, you'll fill up your hard disk. You can keep things under control by periodically cleaning out your projects' Debug directories, or you can use the /Fp compiler option to reroute PCH files to a common directory.