How to Fix .Pch File Missing on Build

How to fix .pch file missing on build?

NOTE: Later versions of the IDE may use "pch" rather than "stdafx" in the default names for related files. It may be necessary to substitute pch for stdafx in the instructions below. I apologize. It's not my fault.

  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.

Lucky 13. Cross your fingers and hit Build.

Compile Error: Cannot open precompiled header.pch -- No such file or directory

There are 2 options to solve this:

  • Rebuild the full project. This should (re)create the precompiled header (or select Build/Clean Solution first).

  • Turn off precompiled headers. Project settings / C/C++ / Precompiled headers / Not Using Precompiled Headers.

Trying to introduce Unit Testing to a project, but .pch file missing

The problem was that the project had been renamed at an earlier date.

Searching the Build Settings for oldname and updating them all to newname means that it's now looking for the files in the correct places.

xcode 6 pch.file not found

i solved it - in targets delete xctest target and it compiled

How to fix PCH error?

This is often a caching problem. Usually it can be resolved by holding down the Option key and choosing Product > Clean Build Folder...

Xcode .pch error while compiling. clang file not found

This can occur (not your fault) when the Xcode project file database gets messed up such that the referenced file does not appear in the navigation area but is still somehow included in one of the various list of files used for the build phases.

To see if this is the case:

  • In the Finder, right click on the project file and select 'Show Package Contents'
  • Right click on the file 'project.pbxproj' and 'Open With->TextEdit.app'
  • In TextEdit menu: 'Edit->Find->Find...' [or command-F] then enter '.pch'
  • Look at all occurrences of '.pch' [command -G to move to next one]

If you find occurrences of '../firstFoo-Prefix.pch' then your project file is corrupted. Looking at the context of the occurrence(s) will give you some indication of which area the corruption occurs in (e.g. build phase compile files list).

Sometimes just deleting those references (after having backed-up the project file of course) has worked for us but other times it just makes matters worse. The safest recovery is to create a new project file and copy over all the folder groups and settings manually. Your source code is all fine, it's just the cross-references and build settings that need reworking.



Related Topics



Leave a reply



Submit