To combat a long build time, I consolidated common headers across 20+ projects into a single precompiled header, to be shared. The pch file is generated from a separate project (pch.vcproj with stdafx.cpp/h), and it works with clean builds and incremental builds (from editing one of the files belonging to the 20+ projects), but I get compile errors when I choose Rebuild.
Before presuming a bug, I'd like to ask the forum for help. There are several things that have to be done to get this to work, and unfortunately, I'll have to reveal them to legitimize asking for help. For sake of generality, lets say one of these projects is A.vcproj.
For PCH\PCH.VCPROJ:
(This is a completely default configuration for creating precompiled headers)
1. In the properties for stdafx.cpp, I set /Yc:stdafx.h, and use default settings for everything else. This will create the precompiled headers pch\release\pch.pch and pch\debug\pch.pch.
For A\A.VCPROJ:
(This is an almost-completely default configuration for using precompiled headers: the exception is step 5.)
1. All pertinent C++ compiler settings match between A.vcproj and pch.vcproj (the compiler checks for this).
2. Under Project Dependencies for A, I choose "pch" so that pch.vcproj will build before A.vcproj builds.
3. In A.vcproj (all files), I set /Yu:stdafx.h, add -I..\pch (so stdafx.h can be found).
4. At the top of all cpp files in A.vcproj, I add #include "stdafx.h".
5. In the properties for A.vcproj, I use /Yu:stdafx.h, but the file is called ..\pch\$(IntDir)\pch.pch, as one would expect to do for sharing precompiled headers.
Doing Clean Solution and then Build Solution produces no errors.
Then doing Rebuild Solution produces the following errors (edited in <solution dir>)
error C2859: <solution dir>\pch\release\vc80.pdb is not the pdb file that was used when this precompiled header was created, recreate the precompiled header.
error C2859: <solution dir>\pch\release\vc80.idb is not the idb file that was used when this precompiled header was created, recreate the precompiled header
To summarize, Clean + Build works, Rebuild doesn't work, and Clean+Rebuild doesn't work. If the Visual C++ team wishes me to file a bug, I can do so.
Also, if anyone knows of a workaround, it would be helpful.
Thanks,
Brian

Rebuild using shared precompiled headers doesn't work
Vibhore
We were using a small "trick" to get it to work in all cases (build and rebuild):
the path for the .pdb file had to contain the sequence of characters "\\..\", for instance "$(TargetDir)\..\pch\pch.pdb".
This trick does not work anymore for VS.NET 2005, so the use of shared precompiled header seems to be totally impossible in this version.
FYI, we have another version of our build process that is managed by Apache Ant (using the VS.NET 2003 compiler), for which shared precompiled header worked.
robert r
Eddy Chang
I'm getting the impression that shared pch's were never supported in VS, despite an old newsgroup posting from that describes the steps that I've taken.
If that's the case, it's a bit of a disappointment, since my code is 95% header-based and is reused across a multitude of small projects.
sunnydhiman
1.) You can't debug.
2.) You can't use multiprocessor building due to the locking of the pch file.
They aren't caveats, but more like showstoppers. I put in a suggestion to support shared pch's in a future release. You can my suggestion louder by voting on it or adding comments.
http://lab.msdn.microsoft.com/productfeedback/viewfeedback.aspx feedbackid=360e0921-f4e3-4318-8b0d-aa364bd690b5
DavidC&#35;2005
I have the same issue, but my .sln has a lot of .vcprj.
When I adopted shared precompiled headers with VS 2003 the compile time and the output files dimension have been reduced about to 25% (by shared pch, using a strong pc, the rebuild time of my solution is about 1 hour, before shared pch it was about 4 hours)
There is a solution with Visual Studio 2005 SP1
Thank you in advance
SwissToni
It's sad, as a "simple" change of the build sequence would most certainly fix te problem (and I think many developers are concerned by this issue since it was a common practice for large C/C++ workspaces)
SusanHX
Please file a bug (at http://lab.msdn.microsoft.com/productfeedback/default.aspx) so that the responsible folks could take a look. I am sure if there is wrokaround it will be posted with their reply as well.
Thanks in advance for raising the issue!
Thanks,
Ayman Shoukry
VC++ Team
daking
All suggestions "late in the game" got postponed for consideration in the next release (Whidbey SP1 or Orcas). They'll probably retriage them.
hafez
I had the same issue and looking for this bug in the Web, I found a link related to VC++ 6.
http://www.tutorialsall.com/VC/Help-needed-265048/
So, applying what this link says, I you modify the stdafx.cpp file, and just remove the space between the comments and the line #include "stdafx.h", the IDE is able to rebuild again.
Hope it helps.
Ryan LeCompte
Thanks for your advice but ... I am not a novice ;-)
The issue is open too
bye
Riccardo
&#160;JD&#160;