135

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?

22 Answers 22

249

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

9
  • 4
    This did not fix the error for me. I've also performing a full clean and deleting the derived data.
    – Ben S
    Mar 18, 2013 at 17:42
  • 6
    Worked for me, except it was under Product > Clean and no need for the command key. (Xcode 4.6.1) Mar 20, 2013 at 17:35
  • 1
    @SteveHaley There is a Product > Clean, but it does a less thorough job. Some people can get buy with Product > Clean, for most Product > Clean Build Folder... is sufficient, and others need the manual removal as indicated in @Sedes answer below.
    – gaige
    Apr 19, 2013 at 12:05
  • 7
    I know its old question, but the above mentioned fix did not help me. Just by deleting Derived Data and building the project again work fine.
    – Ankit Jain
    May 5, 2015 at 12:00
  • 2
    can you just do rm -rf /ios/build? Feb 6, 2017 at 12:43
48

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

3
  • It's important to note that DerivedData is not necessarily where your Build folder is, this helped me a lot, thanks!
    – Etheryte
    Dec 28, 2016 at 6:34
  • 1
    delete moduleCache inside of DerivedData too
    – whtlnv
    Jan 16, 2018 at 0:11
  • You should first try to "clean" as the other answers say. When this doesn't work, I would simply just recursively delete the entire DerivedData folder ... "nuke from orbit ... only way to be sure." @whitelionV this would also rm moduleCache and everything else in there.
    – wcochran
    Jan 16, 2018 at 18:30
39

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

6
  • 2
    This fixed this problem for me. For me it is because I have a command-line driven build.
    – ThomasW
    Mar 21, 2013 at 2:10
  • 2
    If this is your case you can find that folder in the Xcode build transcript. I looked for the string "SharedPrecompiledHeaders" Apr 19, 2013 at 13:13
  • 6
    Yes, this is the right solution. Specially if you build from command line or you have a build script. The precompiled header location can be found in the build settings, "Build locations"->Precompiled headers cached path.
    – karim
    Apr 24, 2013 at 8:55
  • How do you find the var directory?
    – GoldenJoe
    Dec 9, 2014 at 8:24
  • 1
    @GoldenJoe Open Finder, Shift-Cmd-G and type /var
    – Sedes
    Dec 9, 2014 at 22:06
25

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

0
18

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

3
  • Yes, you are right. None of the above works for me. Just delete the folder it mentioned, and rebuild, that's it.
    – Zhang Buzz
    May 29, 2017 at 14:57
  • This is the correct answer. Clean/delete DerivedData doesn't not work for me after moving the project to other path.
    – Bill Chan
    Apr 30, 2020 at 18:55
  • 1
    This worked for me with a command line build. For anyone stumbling upon this, deleting the second path is what you need to do (the one the error says is currently the path). Jan 4, 2021 at 16:39
14

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

1
  • Yep, also on react-native and build works from Xcode but not from CLI using npm run ios. Removing cache as suggested solved the problem.
    – dakt
    Oct 11, 2018 at 8:54
13

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

2
7

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

The solution is just delete the .build directory.

6

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

5

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

1
  • My cache path was in the build folder /build/ModuleCache/. Removing it from the old location didn't do the trick
    – TheJeff
    Aug 6, 2017 at 14:55
5

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
1
  • This is something I can easily use in a script, so I like it... I haven't discovered any bad cases [yet]
    – Matt
    Oct 16, 2014 at 19:56
4

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.

3

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.

0
3

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

2

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

2

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.

2
  • This worked for me. I deleted the SharedPrecompiledHeaders directory, clean build, clean build folder, etc etc. This was on Xcode 5.1
    – migs647
    Mar 26, 2014 at 17:58
  • Where is the PCH file?
    – TheJeff
    Aug 6, 2017 at 14:47
2

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.

1
  • 2
    There is an answer identical to this with more detail above posted by @sedes. Please try not to post duplicate answers. Apr 22, 2013 at 3:08
2

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

0
2

You may try cleaning the product or the build folder:

SHIFT + COMMAND + K

OPTION + SHIFT + COMMAND + K

0
2

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.

1

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.

2
  • Could you elaborate a bit please ? Dec 10, 2015 at 9:01
  • Closing Xcode, running rm -rf ~/Library/Developer/Xcode/DerivedData in Terminal, and then opening Xcode did it for me. I also made sure my locations (Xcode -> Preferences -> Locations) were all default.
    – sman591
    Feb 25, 2016 at 17:49
0

I just deleted DerivedData and worked for me.

Not the answer you're looking for? Browse other questions tagged or ask your own question.