Xcode 无法发出预编译头文件?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/49716615/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 10:36:32  来源:igfitidea点击:

Xcode failed to emit precompiled header?

objective-cswiftxcodeheaderfmdb

提问by battlmonstr

thanks in advance for the help you will give me.

在此先感谢您对我的帮助。

I have searched this for half a day over the internet yesterday and two hours now and I haven't found anything (more than those two links that did not help FMDatabase.h not found when using route-me library& Failed to emit precompiled header for bridging header)

我现在已经昨天,两小时搜索这半天在互联网上,我还没有发现任何东西(超过这两个环节没有帮助使用路由我库时FMDatabase.h没有发现未能发出预编译头用于桥接标题

So here is my problem : I just had in hands a project that a previous developer has been working on, and when I try to launch it, here I have two errors :

所以这是我的问题:我刚刚拥有一个以前的开发人员一直在从事的项目,当我尝试启动它时,我有两个错误:

failed to emit precompiled header '/Users/me/Library/Developer/Xcode/DerivedData/Alavoc-arfzuirebtfstncdztyvgvtpcbgw/Build/Intermediates.noindex/PrecompiledHeaders/Alavoc-Bridging-Header-swift_1I75NH5N40QPS-clang_30E4RG2TSVLXF.pch' for bridging header '/Users/me/Downloads/Alavoc-ios-master/Alavoc/bridge/Alavoc-Bridging-Header.h'

/Users/me/Downloads/Alavoc-ios-master/Alavoc/externalLib/customClass/customClassViewController.h:13:9: error: 'FMDB/FMDB.h' file not found

未能发出预编译的头文件 '/Users/me/Library/Developer/Xcode/DerivedData/Alavoc-arfzuirebtfstncdztyvgvtpcbgw/Build/Intermediates.noindex/PrecompiledHeaders/Alavoc-Bridging-Header-swift_1I75NH5N40QPS-clang2dsVheader'/Alavoc-arfzuirebtfstncdztyvgvtpcbgw/我/下载/Alavoc-ios-master/Alavoc/bridge/Alavoc-Bridging-Header.h'

/Users/me/Downloads/Alavoc-ios-master/Alavoc/externalLib/customClass/customClassViewController.h:13:9: 错误: 'FMDB/FMDB.h' 文件未找到

There is also one fatal error wroten like this (even if I only have two errors counted, this one appears in the log above the two other ones previously described)

还有一个这样写的致命错误(即使我只计算了两个错误,这个错误出现在前面描述的另外两个错误之上的日志中)

fatal error: module file '/Users/me/Library/Developer/Xcode/DerivedData/ModuleCache/30E4RG2TSVLXF/Foundation-3DFYNEBRQSXST.pcm' is out of date and needs to be rebuilt: signature mismatch note: imported by '/Users/me/Library/Developer/Xcode/DerivedData/Alavoc-arfzuirebtfstncdztyvgvtpcbgw/Build/Intermediates.noindex/PrecompiledHeaders/Alavoc-Bridging-Header-swift_1I75NH5N40QPS-clang_30E4RG2TSVLXF.pch' /Users/me/Downloads/Alavoc-ios-master/Alavoc/bridge/Alavoc-Bridging-Header.h:13:9: note: in file included from /Users/me/Downloads/Alavoc-ios-master/Alavoc/bridge/Alavoc-Bridging-Header.h:13: #import "customClassViewController.h"

致命错误:模块文件“/Users/me/Library/Developer/Xcode/DerivedData/ModuleCache/30E4RG2TSVLXF/Foundation-3DFYNEBRQSXST.pcm”已过期,需要重建:签名不匹配注意:由“/Users/me”导入/Library/Developer/Xcode/DerivedData/Alavoc-arfzuirebtfstncdztyvgvtpcbgw/Build/Intermediates.noindex/PrecompiledHeaders/Alavoc-Bridging-Header-swift_1I75NH5N40QPS-clang_30E4RG2TSVLXF.pch/Alavoc-arfzuirebtfstncdztyvgvtpcbgw /Build/Intermediates.noindex/PrecompiledHeaders Alavoc-Bridging-Header.h:13:9:注意:在 /Users/me/Downloads/Alavoc-ios-master/Alavoc/bridge/Alavoc-Bridging-Header.h:13 包含的文件中:#import "customClassViewController.h" H”

customClassViewController.h line 13 :

customClassViewController.h 第 13 行:

#import <FMDB/FMDB.h>

I guess those errors are linked. Do you have any idea where it could come from ?

我想这些错误是相互关联的。你知道它可能来自哪里吗?

Thanks in advance for your help guys, I really appreciate it!

在此先感谢您的帮助,我真的很感激!

Edit for battlmonster (new errors) :

编辑battlmonster(新错误):

Here are the two errros (file not found (in Alavoc-Bridging-Header.h FMDB.h not found)) and failed to emit precompiled header :

这是两个错误(未找到文件(在 Alavoc-Bridging-Header.h 中未找到 FMDB.h))并且未能发出预编译头:

fatal error: file '/Users/me/Downloads/Alavoc-ios-master/Alavoc/bridge/Alavoc-Bridging-Header.h' has been modified since the precompiled header '/Users/me/Library/Developer/Xcode/DerivedData/Alavoc-arfzuirebtfstncdztyvgvtpcbgw/Build/Intermediates.noindex/PrecompiledHeaders/Alavoc-Bridging-Header-swift_1I75NH5N40QPS-clang_30E4RG2TSVLXF.pch' was built note: please rebuild precompiled header '/Users/me/Library/Developer/Xcode/DerivedData/Alavoc-arfzuirebtfstncdztyvgvtpcbgw/Build/Intermediates.noindex/PrecompiledHeaders/Alavoc-Bridging-Header-swift_1I75NH5N40QPS-clang_30E4RG2TSVLXF.pch' /Users/me/Downloads/Alavoc-ios-master/Alavoc/bridge/Alavoc-Bridging-Header.h:29:9: error: 'FMDB/FMDB.h' file not found

import

    ^ 1 error generated. <unknown>:0: error: failed to emit precompiled header

'/Users/me/Library/Developer/Xcode/DerivedData/Alavoc-arfzuirebtfstncdztyvgvtpcbgw/Build/Intermediates.noindex/PrecompiledHeaders/Alavoc-Bridging-Header-swift_1I75NH5N40QPS-clang_30E4RG2TSVLXF.pch' for bridging header '/Users/me/Downloads/Alavoc-ios-master/Alavoc/bridge/Alavoc-Bridging-Header.h'

致命错误:文件 '/Users/me/Downloads/Alavoc-ios-master/Alavoc/bridge/Alavoc-Bridging-Header.h' 自预编译头文件 '/Users/me/Library/Developer/Xcode/DerivedData 以来已被修改/Alavoc-arfzuirebtfstncdztyvgvtpcbgw/Build/Intermediates.noindex/PrecompiledHeaders/Alavoc-Bridging-Header-swift_1I75NH5N40QPS-clang_30E4RG2TSVLXF.pch'已构建注意:请重建预编译头文件'/LibracutApcbvargt/LibraryvtcAvetg/Usersdvoc/LibracvtcAvetcAvetg/Usersdvoc /Build/Intermediates.noindex/PrecompiledHeaders/Alavoc-Bridging-Header-swift_1I75NH5N40QPS-clang_30E4RG2TSVLXF.pch' /Users/me/Downloads/Alavoc-ios-master/Alavoc/bridge/Alavoc-Bridging-Header.h:29:9:9错误:找不到“FMDB/FMDB.h”文件

进口

    ^ 1 error generated. <unknown>:0: error: failed to emit precompiled header

'/Users/me/Library/Developer/Xcode/DerivedData/Alavoc-arfzuirebtfstncdztyvgvtpcbgw/Build/Intermediates.noindex/PrecompiledHeaders/Alavoc-Bridging-Header-swift_1I75NH5N40QPS-clang_30E4RGpgingsAvoca/Download/Users/Intermediates.noindex -ios-master/Alavoc/bridge/Alavoc-Bridging-Header.h'

回答by battlmonstr

This error is about a malformed bridging header. The bridging header is a special header file which lists all Objective-C header files with classes that must be accessible from Swift code. All the bridging header definitions are precompiled in a way to be ready to use from Swift. In your case the bridging header is "Alavoc/bridge/Alavoc-Bridging-Header.h", and it includes a header for customClassViewController.h (from Alavoc/externalLib/customClass), which indicates that your fellow developer wants that customClassViewController is accessible in Swift code.

此错误与格式错误的桥接头有关。桥接头文件是一个特殊的头文件,它列出了所有带有必须可以从 Swift 代码访问的类的 Objective-C 头文件。所有桥接头定义都以一种可以在 Swift 中使用的方式进行预编译。在您的情况下,桥接标头是“Alavoc/bridge/Alavoc-Bridging-Header.h”,它包括 customClassViewController.h 的标头(来自 Alavoc/externalLib/customClass),这表明您的开发伙伴希望 customClassViewController 是可访问的在 Swift 代码中。

Now the confusing thing about the bridging header is that it is not recursively including everything, i.e. it just looks on the first level of definitions, and if you import something in your import that you want in Swift, you have to add it to the bridging header explicitly, or else you'll probably get a warning (or an error sometimes). Say you have #import "A.h"in the bridging header, and you have #import "B.h"inside "A.h", then you likely would have to add "B.h" to the bridging header as well.

现在关于桥接标头的令人困惑的事情是它没有递归地包含所有内容,即它只查看第一级定义,并且如果您在导入中导入一些您想要在 Swift 中使用的内容,则必须将其添加到桥接明确标头,否则您可能会收到警告(或有时会出现错误)。假设您#import "A.h"在桥接头中,并且#import "B.h"在“Ah”内部,那么您可能还必须将“Bh”添加到桥接头中。

Now in your example A = customClassViewController, and B = FMDB, and normally you would need to add FMDB to the bridging header, but the thing is that you most likely don't want exporting FMDB to Swift via your bridging header, because it is not meant for this (it is for your own objc code and not for 3rd party libs).

现在在你的例子中 A = customClassViewController, and B = FMDB,通常你需要将 FMDB 添加到桥接头,但问题是你很可能不希望通过你的桥接头将 FMDB 导出到 Swift,因为它是不是为了这个(它是为了你自己的 objc 代码而不是 3rd 方库)。

The solution would be to remove line 13 from your "customClassViewController.h". This would likely fix the bridging header compilation, but probably break the customClassViewController, so you need to include FMDB in "customClassViewController.m" and most likely adapt the "customClassViewController.h" to not have anything related to FMDB (or forward-declare those usages with @class X;).

解决方案是从“customClassViewController.h”中删除第 13 行。这可能会修复桥接头编译,但可能会破坏 customClassViewController,因此您需要在“customClassViewController.m”中包含 FMDB,并且很可能将“customClassViewController.h”调整为与 FMDB 无关(或向前声明那些与@class X;) 的用法。

If you move #import <FMDB/FMDB.h>to your implementation (.m) files and still get error: 'FMDB/FMDB.h' file not found, it is likely about FMDB path not being listed in your header search paths.

如果您移至#import <FMDB/FMDB.h>您的实现 (.m) 文件并仍然获得error: 'FMDB/FMDB.h' file not found,则可能是 FMDB 路径未列在您的标头搜索路径中。

To solve the last one just include the right path in your "Header Search Paths" in Xcode build settings. Let's say FMDB is located at /Users/me/Downloads/Alavoc-ios-master/Alavoc/ASDASD/FMDB (and you have /Users/me/Downloads/Alavoc-ios-master/Alavoc/ASDASD/FMDB/FMDB.h inside), Then you need to open Xcode project settings - select your target on the left - select "Build Settings" on the top - find "Header Search Paths" setting and add /Users/me/Downloads/Alavoc-ios-master/Alavoc/ASDASD path

要解决最后一个问题,只需在 Xcode 构建设置的“标题搜索路径”中包含正确的路径。假设 FMDB 位于 /Users/me/Downloads/Alavoc-ios-master/Alavoc/ASDASD/FMDB(你有 /Users/me/Downloads/Alavoc-ios-master/Alavoc/ASDASD/FMDB/FMDB.h里面),然后你需要打开Xcode项目设置——在左边选择你的目标——在顶部选择“Build Settings”——找到“Header Search Paths”设置并添加/Users/me/Downloads/Alavoc-ios-master/ Alavoc/ASDASD 路径

回答by cpl_maverick

If you are using cocoapod and it is a framework, suggesting you NOT to include this in pre-compiled header.

如果您使用的是 cocoapod 并且它是一个框架,则建议您不要将其包含在预编译头文件中。

Instead, objc files, use:

相反,objc 文件,使用:

@import framework_name;

@import framework_name;