92

Xcode 7 引入了Bitcode,它是某种 LLVM 中间二进制文件,这意味着 Apple 的服务器可以为不同的架构重新编译我的应用程序,而无需我的参与。

在 Lookback,我在我们的库中分发了一个静态归档框架。似乎当您使用“构建和存档”以外的任何东西进行构建时,比特码实际上并没有发送到我的库中,并且任何在他们的应用程序中与我的库链接并尝试在启用比特码的情况下进行构建和存档的人都会得到其中一个两个警告:

  • ld: 'Lookback(Lookback.o)' does not contain bitcode. You must rebuild it with bitcode enabled (Xcode setting ENABLE_BITCODE), obtain an updated library from the vendor, or disable bitcode for this target.(如果 lib 是用 Xcode 6 构建的)
  • ld: warning: full bitcode bundle could not be generated because 'Lookback(Lookback.o)' was built only with bitcode marker. The library must be generated from Xcode archive build with bitcode enabled (Xcode setting ENABLE_BITCODE)(如果 lib 是使用 Xcode 7 和普通的 xcodebuild 构建的)

我有一个构建设备+模拟器通用二进制文件的构建脚本,所以我不能使用构建和存档,而是xcodebuild从我的脚本的命令行运行。如何xcodebuild生成正确的启用位码的库?

4

4 回答 4

141

Bitcode 是一个编译时功能(不是链接时功能),这意味着每个 .o 文件在使用 bitcode 构建时都应该包含一个名为 __bitcode 的额外部分。您可以通过运行来确认您的二进制文件是否与位码兼容otool -l (my .o or .a file) | grep __LLVM

当您正常构建时,Xcode 会将构建标志添加-fembed-bitcode-marker到任何 clang 调用中。这似乎是某种“如果启用了位码,这就是位码将去的地方”的事情,实际上并没有启用位码。

当您“构建和存档”时,此标志将替换为-fembed-bitcode,它确实构建了启用 Bitcode 的二进制文件。

似乎有两种xcodebuild使用方法-fembed-bitcode

  • 使用“归档”操作,如xcodebuild -target LookbackSDK archive代替xcodebuild -target LookbackSDK build. 这具有将二进制文件放入 Xcode Organizer 而不是build/文件夹的副作用,尽管您可以通过使用-exportArchive -archivePath ./build(感谢@JensAyton)来解决这个问题
  • 通过添加其他 C 标志来强制使用标志OTHER_CFLAGS="-fembed-bitcode"。您的xcodebuild调用看起来像xcodebuild OTHER_CFLAGS="-fembed-bitcode" -target LookbackSDK build.

后者是我选择的,这样我就不必更改我的构建系统,但它会为每个文件生成警告,因为现在两者都-fembed-bitcode-marker-fembed-bitcode发送到 clang。幸运的是,后者获胜,生成了一个支持 Bitcode 的库!

资源

于 2015-07-17T23:37:34.007 回答
43

With Xcode 8, I couldn't get OTHER_CFLAGS="-fembed-bitcode" to work. I kept running into something along the lines of was built without full bitcode. All frameworks and dylibs for bitcode must be generated from Xcode Archive or Install build when I tried to create an Archive build of an app containing my static framework.

What I was really looking for was this:

BITCODE_GENERATION_MODE=bitcode

I'm actually using a Run Script inside of an aggregate target, the full xcodebuild line looks like this (just for reference):

xcodebuild BITCODE_GENERATION_MODE=bitcode OTHER_CFLAGS="-fembed-bitcode" -target "${PROJECT_NAME}" ONLY_ACTIVE_ARCH=NO -configuration ${CONFIGURATION} -sdk iphoneos BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" clean build

于 2017-09-08T18:40:20.923 回答
17

为静态库添加位码支持后,它将与 Xcode 6 不兼容。应用程序不会存档。

我想清楚地提到比特码的设置,因为@nevyn 的回答让我有点困惑。

转到构建设置,搜索“自定义编译器标志”。添加-fembed-bitcode. 这将使用位码构建您的库。

于 2015-09-15T10:11:35.633 回答
7

Select project On Build Settings -> Other C flags, set Debug to -fembed-bitcode-marker and Release to -fembed-bitcode

On Build Settings, click on the + sign at the top to add a user-defined build setting with the name BITCODE_GENERATION_MODE, and set Debug to marker, Release to bitcode

Edit schema as Release Then click the desired library. A file and get the build path. Get the library form Release folder.

于 2018-08-15T04:47:48.383 回答