How to fix PCH error?

XcodeClangPrecompiled Headers

Xcode Problem Overview


When I try to build my app in Xcode, I get this error message:

> PCH file built from a different branch ((clang-425.0.24)) than the > compiler ((clang-425.0.27))

It doesn't happen before, but this was the first build after updating Xcode.

Other apps work, but not this specific one.

If I turn off the "Precompile Prefix Header" setting, it works.

How do I fix this error and still keep that setting on?

Xcode Solutions


Solution 1 - Xcode

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

Solution 2 - Xcode

Delete the DerivedData folder for the project. Look under Xcode preferences -> Locations to see where you save it.

Solution 3 - Xcode

It seems that the Product > Clean Build Folder... (with Option key pressed) works for most people. See the selected answer by @gaige.

If you're unlike most people (myself included) and this still causes you trouble XCode has likely left your shared precompiled headers elsewhere. For me they were in a folder similar to this:

/var/folders/<some random two characters>/<some random string>/C/com.apple.Xcode.502/SharedPrecompiledHeaders

I just deleted the entire SharedPrecompiledHeaders folder and that solved things for me. I wouldn't go touching much else in here though...

Solution 4 - Xcode

Go to Xcode Preferences->Locations (as mentioned in the answer by wcochran) and simply rename your DerivedData folder. I simply changed mine from "DerivedData" to "DerivedData2" and that forced the system to stop referencing the old location. This fixed it for me when none of the other answers worked. See pic:

enter image description here

Solution 5 - Xcode

None of the other options worked for me, here is what fixed it:

I deleted the cache folder at /Users/(Yourname)/Library/Developer/Xcode/DerivedData/ModuleCache/(renaming it works too).

Try deleting the folder mentioned in the error, if your error looks something like this:

PCH was compiled with module cache path '/Users/User/Library/Developer/Xcode/DerivedData/ModuleCache/75YIWZVTEAO8', but the path is currently '/Users/Stan/Library/Developer/Xcode/DerivedData/ModuleCache/75YIWZVTEAO8

Solution 6 - Xcode

In your ios project directory, go to build and delete ModuleCache folder. Run react-native run-ios again, it should work as expected. Summary - rm -rf ios/build/ModuleCache

Solution 7 - Xcode

Deleting the Build and DerivedData folders from the project location in Finder worked for me.

Solution 8 - Xcode

I met this error when trying to build a project with Swift Package Manager.

The solution is just delete the .build directory.

Solution 9 - Xcode

After upgrading Xcode I was getting this with multiple projects. Clean Build Folder and Clean had no effect - @sedes answer and @josema.vitaminew 's comment did it for me. But it can be tricky unless you use a bit of cunning, so here's a step by step shortcut:

  1. go to the build log that failed
  2. use cmd-f "SharedPrecompiledHeaders" to find it (it will be in the middle of a massive horrible complex commandline)
  3. drag-select the text "SharedPrecompiledHeaders" and all the characters BEFORE but NOT AFTER it until you get to the start of that path bit (still in the middle of the big block of text) e.g. for me: "/var/folders/03/n71d4r551jv40j5nb8r9fjy80000gn/C/com.apple.Xcode.501/SharedPrecompiledHeaders
  4. open Finder
  5. menu: Go -> Go to folder...
  6. copy/paste the selected path
  7. in "SharedPrecompiledHeaders" delete ALL sub-folders (this is safe: it is only cached data)

...and now all your projects will be "Fixed", but will have to re-build themselves first time with zero caching (so the NEXT build ONLY will be slower than normal).

Solution 10 - Xcode

Specially if you build from command line or you have a build script, cleaning xcode target is not enough. You have delete this folder.

The precompiled header location can be found in the

Target -> build settings => "Build locations" -> Precompiled headers cached path

Delete this folder with,

#rm -fr SharedPrecompiledHeaders

enter image description here

Solution 11 - Xcode

in my case I got rid of all files under SharedPrecompiledHeaders this way and everything started to work fine:

sudo find /var/folders/ -type d -name "SharedPrecompiledHeaders" | xargs -n 1 -I dir sudo find dir -name \* -type f -delete

Solution 12 - Xcode

For me this would always happen when I copy my project to another location. I'd do this to push it into a repo or something.

I have to delete the Build folder (rm -rf Build/) in the old and new locations to get it working. It makes sense because the Build folder will have data that is irrelevant to the new location.

Cleaning Derived Data or deleting the sharedPrecompiledHeaders folders didn't really do it in this case.

Solution 13 - Xcode

If it's not solved by cleaning. It's a build cache problem - hold down Option key and navigate to Product > Clean Build Folder. That fixed my problem.

Solution 14 - Xcode

In my case Xcode was creating the DerivedData folder in my project main bundle(/Users/Path_to_your_project_source_code/YourProjectName/DerivedData)

I just deleted this folder from my source code bundle and now it is working.

To check Go to Xcode Preferences->Locations and see if DerivedData is selected to "Relative". See the picture below enter image description here

Solution 15 - Xcode

you should holding down "shift + command + C",and then you will build succeed

Solution 16 - Xcode

You may try cleaning the product or the build folder:

SHIFT + COMMAND + K

OPTION + SHIFT + COMMAND + K

Solution 17 - Xcode

Cleaning and/or deleting derived data did not work for me. What did work is touching/saving the .pch file (add a character, then delete it) to force it to be rebuilt. This did the trick.

Solution 18 - Xcode

If doing a clean build does not work for you, look for the PCH files in /var/folders/../SharedPrecompiledHeaders and remove the PCH files, which worked for me.

Solution 19 - Xcode

UPDATED

This worked perfectly for me:

  • Close your project or workspace.
  • In Finder: ⇧shift+⌘cmd+G
  • Paste: ~/Library/Developer/Xcode/DerivedData/
  • Delete the ModuleCache folder and empty trash.
  • Open up your project.
  • Clean: ⇧shift+⌘cmd+K
  • Build: ⌘cmd+B

xCode 7.3.1
reference here

Solution 20 - Xcode

If you are doing a command line build via xcodebuild, then see if the -derivedDataPath BUILD_DIR option is used. If so, your ModuleCache.noindex directory will be in the BUILD_DIR instead of the normal Xcode location. Delete the ModuleCache.noindex directory and you will be all set.

I ran into this situation because I am building a React Native app, and the iOS client is typically built from the command line via the React Native toolset.

Solution 21 - Xcode

I've tried cleaning the project and cleaning the build folder which both didn't work.

After that, I quit xCode completely, deleted the derived data folder at its standard location: ~/Library/Developer/Xcode/DerivedData, started xCode again and built the project.

That seemed to have resolved the problem for me.

Solution 22 - Xcode

I just deleted DerivedData and worked for me.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionMacro206View Question on Stackoverflow
Solution 1 - XcodegaigeView Answer on Stackoverflow
Solution 2 - XcodewcochranView Answer on Stackoverflow
Solution 3 - XcodeSedesView Answer on Stackoverflow
Solution 4 - XcodeAlyoshakView Answer on Stackoverflow
Solution 5 - XcodeStan TatarnykovView Answer on Stackoverflow
Solution 6 - XcodeRitik RishuView Answer on Stackoverflow
Solution 7 - XcodespfursichView Answer on Stackoverflow
Solution 8 - XcodeZigii WongView Answer on Stackoverflow
Solution 9 - XcodeAdamView Answer on Stackoverflow
Solution 10 - XcodekarimView Answer on Stackoverflow
Solution 11 - XcodeHamid TavakoliView Answer on Stackoverflow
Solution 12 - XcodeTheJeffView Answer on Stackoverflow
Solution 13 - XcodeVardhanView Answer on Stackoverflow
Solution 14 - XcodeDilip SaketView Answer on Stackoverflow
Solution 15 - XcodePeter ZhuView Answer on Stackoverflow
Solution 16 - XcodeMateusView Answer on Stackoverflow
Solution 17 - XcodeAlfie HanssenView Answer on Stackoverflow
Solution 18 - XcodeJonathan LinView Answer on Stackoverflow
Solution 19 - XcodeDaniel MorandiniView Answer on Stackoverflow
Solution 20 - XcodephatmannView Answer on Stackoverflow
Solution 21 - XcodeRamsy de VosView Answer on Stackoverflow
Solution 22 - XcodeKAUSHIK PARMARView Answer on Stackoverflow