The information in this article applies to:
- The Visual Workbench included with:
Microsoft Visual C++, 32-bit Edition, version 2.0, 2.1, 2.2, and 4.0
SUMMARY
In some cases, it is beneficial to share precompiled header (.pch) files
among several projects. However, the Visual Workbench can't use the program
database (.pdb) files because project-specific information related to each
.pch file is stored in the .pdb files. This article explains how to use
.pch files without using .pdb files in the versions of Visual C++ listed at
the beginning of this article.
For information about about the 16-bit Visual Workbench, please see the
following article in the Microsoft Knowledge Base:
ARTICLE-ID: Q117780
TITLE : Using .PCH Files Across Projects in Visual Workbench
MORE INFORMATION
Step-by-Step Procedure
To use a common precompiled header among different projects, first
determine which header file you wish to use. (If all the projects have been
generated by AppWizard, the stdafx.h file is the same for each, so it is a
good candidate for a shared precompiled header.) Once you've made your
choice, copy the header file into a common directory.
Now, for each project that will share the precompiled header, do the
following:
- Delete the shared header file from the individual project directories.
- For each .cpp file that includes the file being used for shared
precompiled header, specify an explicit path to the header. For
example, suppose that stdafx.h is the designated to be the shared
header file and a .cpp file contains the following:
#include "stdafx.h"
If the new location of the header file is c:\common\headers, then the
above statement in the .cpp file should be changed to the following:
#include "c:\common\headers\stdafx.h"
- With Visual C++ 2.x, choose Settings from the Project menu. With Visual
C++ 4.0, choose Settings from the Build menu.
- Click the C/C++ tab.
- Choose Precompiled Headers from the Category list box.
- With Visual C++ 2.x, in the Precompile through Header edit box, type
the complete path of the common header. With Visual C++ 4.0, select
Automatic use of Precompiled Headers and specify the complete path to
the header file in the enabled Through header edit control. (The path
to use is the same path specified in Step 2 above.)
- Click the C/C++ tab, and choose General from the Category list box.
- Choose the "C7 Compatible" from the "Debug Info" List box. This tells
the compiler not to place any of the precompiled header information into
the .pdb file, which keeps inconsistency errors from occurring in that
file.
- Click OK to accept these changes and to close the Project Settings
dialog box.
- Click the Update All Dependencies before rebuilding the project so
that the compiler will use the new common header file. With Visual C++
2.x, this option is on the Project menu; with Visual C++ 4.0, this
option is on the Build menu.
|