Sam Mackrill Sam Mackrill - 11 months ago 75
C++ Question

How to fix .pch file missing on build?

When I build my c++ solution in Visual Studio 2008 it complains that the xxxxx.pch file is missing. Is there a setting I am missing to get the pre-compiled headers back?

here is the exact error for completeness:

Error 1 fatal error C1083: Cannot open precompiled header file: 'Debug\xxxxx.pch': No such file or directory

Answer Source
  1. Right-click on your project in the Solution Explorer.
  2. Click Properties at the bottom of the drop-down menu.
  3. At the top left of the Properties Pages, select All Configurations from the drop-down menu.
  4. Open the C/C++ tree and select Precompiled Headers
  5. Precompiled Header: Select Use (/Yu)
  6. Fill in the Precompiled Header File field. Standard is stdafx.h
  7. Click Okay

  8. If you do not have stdafx.h in your Header Files put it there. Edit it to #include all the headers you want precompiled.

  9. Put a file named stdafx.cpp into your project. Put #include "stdafx.h" at the top of it, and nothing else.
  10. Right-click on stdafx.cpp in Solution Explorer. Select Properties and All configurations again as in step 4 ...
  11. ... but this time select Precompiled Header Create (/Yc). This will only bind to the one file stdafx.cpp.
  12. Put #include "stdafx.h" at the very top of all your source files. (Unix or cygwin users: find . -name "*.cpp" | xargs -n1 sed -i '1s/^/#include "stdafx.h"\n/')

Lucky 13. Cross your fingers and hit Build.