Sharing precompiled headers between projects - Repost

  • Thread starter Thread starter JoeS
  • Start date Start date
J

JoeS

Is there anyway to share a single pch file between
projects in VC 7.0? I have 300+ projects each of which
creates its own pch. All projects include the exact same
header files in the precompiled header. Its takes about 7
seconds to create the precompiled header for each project.
That's 35 minutes spent creating precompiled headers for
all project! All of the projects use PDB files for debug
info.

I tried creating Precomp.pch in project Precomp.vcproj.
When I tried using Precomp.pch in a project Foo.vcproj
using /Fp I get this error message:

c:\objd\Foo\vc70.pdb is not the pdb file that was used
when this precompiled header was created, recreate the
precompiled header."

In the pre-build step of Foo.vcproj I tried copying
c:\objd\Precomp\vc70.pdb to c:\objd\Foo\vc70.pdb but this
resulted in the same error message.

Any insight is much appreciated.

Thanks.
Joe
 
Hi Joe,

I have tested your problem. Here are some steps to workaround the problem.
Below is my directory structure.
(Solution)Test-----test1 (project1)
|---------test2 (project2)
If you generate your applications with AppWizard, the STDAFX.H file is the
same in all applications and it is a good example file. Here I use it as an
example.

1. Create a new blank solution and add all projects into it.
2. Copy the header file into the desired common directory (here is Test
directory) and delete it from the project directories.
3. In each .CPP file that includes the common PCH file, specify a
fully-qualified path to the header file. Here I modified the code as below
#include "C:\Test\stdafx.h"
4. For each project, opens its Project Property Pages
1) Navigates to ¡°Configuration Properties¡± -> ¡°C/C++¡± -> ¡°Precompiled
Headers¡±.
i. Modifies the first option as Use Precompiled Header(/Yu) (You should
create the precompiled header first)
ii. Modifies the second option as $(SolutionDir)StdAfx.h
iii. Modifies the three option as $(SolutionDir)$(SolutionName).pch
2) Navigates to ¡°Configuration Properties¡± -> ¡°C/C++¡± -> ¡°Output Files¡
±
i. Modifies the fifth option as ¡°$(SolutionDir)vc70.pdb¡± (this is
used to ensure all projects refer to identical vc70.pdb file.
3) Clicks OK to save the setting.

At this point, future builds use the common PCH files, as desired.
Hope this help.


Regards,

Peter Huang
=============
This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
 
Back
Top