Rebuild using shared precompiled headers doesn't work

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



Answer this question

Rebuild using shared precompiled headers doesn't work

  • Vibhore

    We have experimented the same problem with VS.NET 2003

    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

    I hade the same errors with pdb and idb. I'm currently sharing a precompiled header between 2 projs (1st one creates pch, 2nd uses it). I solved it by also sharing their intermediate dirs. I'm confident this setup works with more projs. I'm satisfied with my solution, I no longer have to flip between /Yu & /Yc instead when ever my precompile header changes it compiles on need.

  • Eddy Chang

    I'm now wondering if shared pch's are a fantasy.  The error I describe here occurs in any build configuration when the C++ Output File settings point to the default location for the pdb file.  When changing this to the one corresponding to the shared pch, the problem goes away in Clean+Build (but not Rebuild).  But then my project becomes undebuggable.  I didn't appreciate this fact until I actually tried debugging.

    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

    When I set it up under VS 2005, I was able to build with two "caveats".
    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&amp;#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

    Unfortunately it looks like your suggestion has been postponed :(

    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

    Hi Brian,
      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

    Hello.
    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


  • &amp;#160;JD&amp;#160;

    Done.  See FDBK38343.
  • Rebuild using shared precompiled headers doesn't work