可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
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?
回答1:
This is often a caching problem. Usually it can be resolved by holding down the Option key and choosing Product > Clean Build Folder...
回答2:
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...
回答3:
Blow away the DerivedData
folder for the project. Look under Xcode preferences -> Locations to see where you save it.
回答4:
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:
回答5:
Deleting the Build
and DerivedData
folders from the project location in Finder worked for me.
回答6:
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
回答7:
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:
- go to the build log that failed
- use cmd-f "SharedPrecompiledHeaders" to find it (it will be in the middle of a massive horrible complex commandline)
- 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
- open Finder
- menu: Go -> Go to folder...
- copy/paste the selected path
- 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).
回答8:
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
回答9:
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
回答10:
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
回答11:
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.
回答12:
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
回答13:
you should holding down "shift + command + C",and then you will build succeed
回答14:
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.
回答15:
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.
回答16:
You may try cleaning the product or the build folder:
SHIFT + COMMAND + K
OPTION + SHIFT + COMMAND + K
回答17:
I met this error when trying to build a project with Swift Package Manager.
The solution is just delete the .build
directory.
回答18:
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.
回答19:
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
回答20:
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.
回答21:
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.