none
Visual C++ 2005 Precompiled Header Bug?

    Question

  • Hello,

    I have converted a project from Visual Studio 2003 to Visual Studio 2005 and noticed the following problem: Changing a header file does not recompile all the required dependants. This happens only with precompiled headers on, when I turn them off, everything works. This did not happen in Visual Studio 2003. (Minimal / Incremental Build are OFF).

    It is most problemtic when what changed in the header are flags, since it links properly the project is built with some files not updated and creates the most obscure bugs.

    Example (just for problem illustration):

    Test.h:

    #define FLAG_ONE 1

    #define FLAG_TWO 2

    Files TestFile.c and TestFile2.c both use the header and flags, I edit Test.h and remove FLAG_ONE definition -> with precompiled headers just one C file recompiles, the project links ok, even so it is linked with old code that depends on FLAG_ONE (which should've thrown an error!).

    Is this known / Is there a workaround instead of disabling precompiled header? (It worked on VC 2003)

    Thanks.

    Monday, November 13, 2006 10:25 PM

Answers

  • I cannot reproduce this. I tried the following:

    - a test.h file that defines those 2 flags

    - #include "test.h" in the stdafx.h file that is generated when the project is created

    -2 .cpp files that both include stdafx.h

    Removing one #define will generate an C2065  'undeclared identifier' error in both .cpp files.

     

    The problem is that I'm using VS2005 SP1 Beta so maybe it has been fixed.

     

    However, precompiled headers should be used only for headers that do not change (or change rarely) like the C/C++ compiler standard headers and the Windows SDK headers. Using precompiled headers for other things can defeat their purpose, for example just removing that #define will trigger the compilation of all files that include the precompiled header and in most cases that means the whole project.

     

    Monday, November 13, 2006 10:56 PM

All replies

  • I cannot reproduce this. I tried the following:

    - a test.h file that defines those 2 flags

    - #include "test.h" in the stdafx.h file that is generated when the project is created

    -2 .cpp files that both include stdafx.h

    Removing one #define will generate an C2065  'undeclared identifier' error in both .cpp files.

     

    The problem is that I'm using VS2005 SP1 Beta so maybe it has been fixed.

     

    However, precompiled headers should be used only for headers that do not change (or change rarely) like the C/C++ compiler standard headers and the Windows SDK headers. Using precompiled headers for other things can defeat their purpose, for example just removing that #define will trigger the compilation of all files that include the precompiled header and in most cases that means the whole project.

     

    Monday, November 13, 2006 10:56 PM
  • Mike, thanks for the quick answer.

    The example I illustrated is - for illustration - of the problem. My project is big and has many files and headers, it is also a C only project (no C++).

    I am not using SP1.

    Moreover, I fear that this problem occurs only in specific project configurations (what headers the project uses /  how the project hierarchy is constructed). This (or the fact that you use SP1) might be why you could not reproduce the problem. It exists for me and is damn annoying, and it's a bugger that it can't be reproduced with small projects.

    I posted the question to see if someone has occured this problem before in the new compiler and if the team is aware of it. It does exist for me.

    Thanks again!

    Tuesday, November 14, 2006 12:38 AM
  • As Mike and yourself indicated, it is very hard to reproduce it from my side. If this is a blocking issue, please log it at http://connect.microsoft.com. Make sure to attach the project reproducing the issue so that the owners can take a look.

    Thanks in advance for taking the time to log the issue!

    Thanks,
    Ayman Shoukry
    VC++ Team
    Tuesday, November 14, 2006 10:48 AM
  • I believe that I may seeing what you are talking about.  People in my software group recently started seeing a c1023 error (unexpected error with pch) occasionally when building large projects.  The problem mysteriously coincided with our update to IE7.  It seems like one or two of our people see the problem every day.  We just clean the project and rebuild.  We have been using VS 2005 and hadn't seen any problems like this until now.  Just out of curiousity, have you recently updated to IE7?

    Sorry I can't be of help, good luck.

    Monday, November 20, 2006 9:05 PM
  • Yes, I have actually installed IE7 about a month ago.

    I can't say if the problem started after installing IE7 (which is weird by itself) but I can say that I have just noticed the problem AFTER installing IE7.

    Monday, November 20, 2006 11:38 PM
  • I have installed Visual C++ 2005 on machine running Vista for debugging compatibility issues.

    On this installation I see this problem regularily. The same project compiles without problems on other machines.

    Regards
    Wolfgang

     

    Microsoft Visual Studio 2005
    Version 8.0.50727.363  (SP.050727-3600)
    Microsoft .NET Framework
    Version 2.0.50727

    Installed Edition: Enterprise

    Microsoft Visual C++ 2005   77642-113-3000004-41290
    Microsoft Visual C++ 2005

    Visual Studio 2005 Team Edition for Developers   77642-113-3000004-41290
    Microsoft Visual Studio 2005 Team Edition for Software Developers

    Visual Studio 2005 Team Explorer   77642-113-3000004-41290
    Microsoft Visual Studio 2005 Team Explorer
    Version 8.0.50727.363

    Microsoft Visual Studio 2005 Team Explorer - ENU Service Pack 1 (KB918525)  

    Wednesday, December 06, 2006 12:11 PM
  • Anyone ever find a solution to this?  I experience it very frequently as well on a VS2005 SP1 system running under Vista Ultimate.  My solution contains 43 C++ projects with > 5000 files.  While it is not blocking, it does waste tremendous time because of the amount of clean rebuilds that must be done.

     

    Thanks.

    Thursday, September 06, 2007 4:45 PM
  • All of our development team have recently experienced this problem after installing Spyware Doctor enterprise edition. I imagine this is a bug in Spyware doctor than rather than Visual Studio.

    Could you possibly have this software installed?
    Monday, March 03, 2008 9:33 AM
  • While we've moved our work to VS2008, we never had Spyware Doctor installed on our systems...

     

    Tuesday, March 04, 2008 2:50 PM
  • So has anyone found a solution for this yet? I have a large (50+ project) solution and its Its quite irritating to have to have to recompile all the time.
    Thursday, May 15, 2008 7:12 PM
  • I am also facing the same issue with the build failing giving:

    fatal error C1023: '.../stdafx.pch' : unexpected error with pch, try rebuilding the pch

    This is very intermittent and really wastes a lot of time. Any solution will be highly appreciated.

    My Visual Studio configuration is as follows:

    Microsoft Visual Studio 2005
    Version 8.0.50727.762  (SP.050727-7600)
    Microsoft .NET Framework
    Version 2.0.50727 SP1

    Installed Edition: Professional

    Microsoft Visual Basic 2005   77626-009-0000007-41004
    Microsoft Visual Basic 2005

    Microsoft Visual C# 2005   77626-009-0000007-41004
    Microsoft Visual C# 2005

    Microsoft Visual C++ 2005   77626-009-0000007-41004
    Microsoft Visual C++ 2005

    Microsoft Visual J# 2005   77626-009-0000007-41004
    Microsoft Visual J# 2005

    Microsoft Visual Web Developer 2005   77626-009-0000007-41004
    Microsoft Visual Web Developer 2005

    Microsoft Web Application Projects 2005   77626-009-0000007-41004
    Microsoft Web Application Projects 2005
    Version 8.0.50727.762

    Crystal Reports    AAC60-G0CSA4B-V7000AY
    Crystal Reports for Visual Studio 2005


    Hotfix for Microsoft Visual Studio 2005 Professional Edition - ENU (KB930859)  
    For more information, visit http://support.microsoft.com/kb/930859

    Microsoft Visual Studio 2005 Professional Edition - ENU Service Pack 1 (KB926601)  

    Security Update for Microsoft Visual Studio 2005 Professional Edition - ENU (KB947738)  

    Friday, February 05, 2010 10:11 AM