iOS 库到 BitCode

iOS library to BitCode

我最近下载了 Xcode 7 beta,Xcode 抱怨我的一些 C 库没有被编译成 BitCode。我将如何告诉 Clang 生成与 iOS 兼容的 BitCode?我在 Whosebug 上看到过类似的答案,但我不知道它们是否适用于为 iOS.

生成 BitCode 库

编辑:

我使用了正确的设置 -fembed-bitcode,但是当我尝试存档时,出现错误: ld:警告:忽略文件 XXXX/XXXX,文件是为存档构建的,不是被链接的体系结构 (arm64)。 当我使用 -fembed-bitcode-marker 时,我可以存档,但我收到错误: 无法生成完整的位码包,因为 XX/XX 仅使用位码标记构建。该库必须从 Xcode 启用位码的存档构建中生成。

有什么问题吗?该库编译成功,但不允许我存档。我创建了一个简单的添加函数并将其放入库中,我得到了相同的症状,所以它不是我正在编译的库。

编辑 2: 您必须使用 bitcode 和 lipo 一起构建 arm64 和 armv7 版本。使用位码并不能消除归档时对胖库的需求。来源:Link

构建静态库时,必须添加以下内容以生成位码:

-fembed-bitcode 

对于动态库,您还需要 link 和

-fembed-bitcode

注意:此命令仅适用于 Xcode7+

关于使用 -fembed-bitcode-marker

的公认答案

You should be aware that a normal build with the -fembed-bitcode-marker option will produce minimal size embedded bitcode sections without any real content. This is done as a way of testing the bitcode-related aspects of your build without slowing down the build process. The actual bitcode content is included when you do an Archive build.

bwilson Apple 员工。 https://forums.developer.apple.com/thread/3971#12225


更具体地说:

  • -fembed-bitcode-marker 只是标记在存档构建后位码在二进制文件中的位置。
  • -fembed-bitcode 实际上完成了完整的位码生成和嵌入,所以这就是构建静态库所需要的。
  • Xcode 本身使用 -fembed-bitcode-marker 进行常规构建(例如部署到模拟器)
  • Xcode 仅使用 -fembed-bitcode 构建存档构建/生产构建(因为只有 Apple 才需要)。

转到构建设置。搜索“自定义编译器标志”。
-fembed-bitcode 添加到 其他 C 标志 。 这将确保在编译时构建的库具有位码兼容性。我为 iOS 64 位和 32 位做了这个,然后将它们合二为一。 奇迹般有效。

既然你们有疑问,这里是设置的屏幕截图:项目目标和SDK目标的设置相同。


位码库不适用于 Xcode 6.

What you need is -fembed-bitcode. When ENABLE_BITCODE is enabled, Xcode builds with -fembed-bitcode-marker for regular builds and with -fembed-bitcode for archive builds. One option simply "marks" where the bitcode would be in the binary after an archive build and enforces the new bitcode rules, while the other actually does the full-on bitcode generation, which is likely slower and thus not enabled on every kind of build.

Syo Ikeda 的 BITCODE 处理指南也可能对您有所帮助:

You can find the full slide deck here.

如果您在将 -fembed-bitcode 添加到其他 C 标志后仍然遇到问题,请在 "Build Options" 下搜索 "Enable Bitcode" 并将其设置为否。这样您就可以正确存档。

如果您正在构建静态库并希望启用位码,只需 (1) ENABLE_BITCODE = YES 可能还不够。

(2) 同样在设置 -fembed-bitcode 时,在 Teamcity

中构建多个文件时仍会抛出以下错误
bitcode bundle could not be generated because ‘/path/fileInYourStaticLib.a(fileInYourStaticLib.o)’ was built without full bitcode. All object files and libraries for bitcode must be generated from Xcode Archive or Install build for architecture arm64

除了上述步骤 (1) 和 (2) 之外,很少 tips/things 考虑帮助我最终解决问题

  1. 确保在 'PROJECT' 和所有 'TARGETS'.

    上将变量 'Other C Flags' 设置为“-fembed-bitcode”
  2. 如果您尝试为多个项目创建静态库,请确保所有项目都已启用 "-fembed-bitcode"

  3. On Build Settings, click on the + sign at the top to add a user-defined build setting with the nameBITCODE_GENERATION_MODE, and set Debug tomarker, Release tobitcode

  4. 如果以上步骤都不行,您也可以试试这个选项。 On Build Settings -> Other C flags, set Debug to-fembed-bitcode-marker, and Release to-fembed-bitcode

这篇博客帮了大忙 https://medium.com/@heitorburger/static-libraries-frameworks-and-bitcode-6d8f784478a9

此外,每次进行上述更改时,请尝试删除 DerivedData,清理 XCode 项目,并可能退出并重新启动 XCode

只是为像我这样的未来菜鸟添加一些细节。

我 运行 在从 unity 构建到 iOS 时用 libVivoxNative.a 解决了这个问题。我不得不在 4 个不同的位置禁用 bitcode:

最初我想我只是为目标 Unity-iPhone 设置了它,而不是项目或 tests/UnityFramework。更改所有 4 个的设置就成功了。