xcode 如何修复 PCH 错误?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15463179/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to fix PCH error?
提问by Macro206
When I try to build my app in Xcode
, I get this error message:
当我尝试在 中构建我的应用程序时Xcode
,我收到以下错误消息:
PCH file built from a different branch ((clang-425.0.24)) than the compiler ((clang-425.0.27))
从与编译器 ((clang-425.0.27)) 不同的分支 ((clang-425.0.24)) 构建的 PCH 文件
It doesn't happen before, but this was the first build after updating Xcode.
以前没有发生过,但这是更新 Xcode 后的第一次构建。
Other apps work, but not this specific one.
其他应用程序可以工作,但不是这个特定的应用程序。
If I turn off the "Precompile Prefix Header"
setting, it works.
如果我关闭"Precompile Prefix Header"
设置,它会起作用。
How do I fix this error and still keep that setting on?
如何修复此错误并仍然保持该设置?
回答by gaige
This is often a caching problem. Usually it can be resolved by holding down the Optionkey and choosing Product > Clean Build Folder...
这通常是一个缓存问题。通常可以通过按住Option键并选择Product > Clean Build Folder...来解决。
回答by wcochran
Delete the DerivedData
folder for the project. Look under Xcode preferences -> Locations to see where you save it.
删除DerivedData
项目的文件夹。查看 Xcode 首选项 -> 位置以查看保存位置。
回答by Sedes
It seems that the Product > Clean Build Folder...(with Option key pressed) works for most people. See the selected answer by @gaige.
似乎Product > Clean Build Folder...(按下 Option 键)适用于大多数人。查看@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:
如果您与大多数人(包括我自己)不同,并且这仍然会给您带来麻烦,那么 XCode 可能会将您共享的预编译头文件留在别处。对我来说,他们在一个类似于这样的文件夹中:
/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...
我刚刚删除了整个 SharedPrecompiledHeaders 文件夹,这为我解决了问题。不过,我不会在这里接触太多其他东西......
回答by Alyoshak
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:
转到 Xcode Preferences->Locations(如 wcochran 的回答中所述)并简单地重命名您的 DerivedData 文件夹。我只是将我的从“DerivedData”更改为“DerivedData2”,这迫使系统停止引用旧位置。当其他答案都不起作用时,这为我解决了这个问题。见图片:
回答by Stan Tatarnykov
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).
我删除了缓存文件夹/Users/(Yourname)/Library/Developer/Xcode/DerivedData/ModuleCache/
(重命名它也有效)。
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
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
回答by spfursich
Deleting the Build
and DerivedData
folders from the project location in Finder worked for me.
从 Finder 中的项目位置删除Build
和DerivedData
文件夹对我有用。
回答by Ritik Rishu
In your ios project directory, go to buildand delete ModuleCachefolder. Run react-native run-ios
again, it should work as expected.
Summary - rm -rf ios/build/ModuleCache
在你的 ios 项目目录中,去构建和删除ModuleCache文件夹。react-native run-ios
再次运行,它应该按预期工作。概括 -rm -rf ios/build/ModuleCache
回答by Adam
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:
升级 Xcode 后,我在多个项目中得到了这个。Clean Build Folder 和 Clean 没有效果 - @sedes 回答和 @josema.vitaminew 的评论为我做了。但是除非您使用一点狡猾,否则它可能会很棘手,因此这里有一个逐步的快捷方式:
- 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)
- 转到失败的构建日志
- 使用 cmd-f "SharedPrecompiledHeaders" 找到它(它将位于一个巨大的可怕的复杂命令行的中间)
- 拖动选择文本“SharedPrecompiledHeaders”和之前但不是之后的所有字符,直到您到达该路径位的开头(仍在大文本块的中间),例如对我来说:“/var/folders/03 /n71d4r551jv40j5nb8r9fjy80000gn/C/com.apple.Xcode.501/SharedPrecompiledHeaders
- 打开 Finder
- 菜单:前往 -> 前往文件夹...
- 复制/粘贴所选路径
- 在“SharedPrecompiledHeaders”中删除所有子文件夹(这是安全的:它只是缓存数据)
...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).
...现在您的所有项目都将被“修复”,但必须第一次使用零缓存重新构建自己(因此 NEXT 构建只会比正常情况慢)。
回答by Hamid Tavakoli
in my case I got rid of all files under SharedPrecompiledHeadersthis way and everything started to work fine:
在我的情况下,我以这种方式摆脱了SharedPrecompiledHeaders下的所有文件,一切都开始正常工作:
sudo find /var/folders/ -type d -name "SharedPrecompiledHeaders" | xargs -n 1 -I dir sudo find dir -name \* -type f -delete
回答by Zigii Wong
I met this error when trying to build a project with Swift Package Manager.
我在尝试使用 Swift Package Manager 构建项目时遇到了这个错误。
The solution is just delete the .build
directory.
解决办法就是删除.build
目录。