Article: Q137515
Product(s): Microsoft C Compiler
Version(s): 2.0,2.1,2.2,4.0
Operating System(s):
Keyword(s): kbide kbVC
Last Modified: 14-NOV-2001
-------------------------------------------------------------------------------
The information in this article applies to:
- Microsoft Visual C++, 32-bit Editions, versions 2.0, 2.1, 2.2, 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:
Q117780 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:
1. Delete the shared header file from the individual project directories.
2. 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"
3. With Visual C++ 2.x, choose Settings from the Project menu. With Visual C++
4.0, choose Settings from the Build menu.
4. Click the C/C++ tab.
5. Choose Precompiled Headers from the Category list box.
6. 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.)
7. Click the C/C++ tab, and choose General from the Category list box.
8. 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.
9. Click OK to accept these changes and to close the Project Settings dialog
box.
10. 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.
Additional query words: 2.00 2.10 2.20 4.00
======================================================================
Keywords : kbide kbVC
Technology : kbVCsearch kbVC400 kbAudDeveloper kbVC220 kbVC200 kbVC210 kbVC32bitSearch
Version : :2.0,2.1,2.2,4.0
Issue type : kbhowto
=============================================================================