如何在启用Bitcode的情况下xcodebuild一个静态库? [英] How do I xcodebuild a static library with Bitcode enabled?

查看:240
本文介绍了如何在启用Bitcode的情况下xcodebuild一个静态库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Xcode 7介绍 Bitcode ,这是一种LLVM中间二进制文件,这意味着Apple的服务器可以在不涉及的情况下重新编译我的应用程序以用于不同的架构。

Xcode 7 introduces Bitcode, which is some sort of LLVM intermediate binary that means Apple's servers can recompile my app for different architectures without my involvement.

在Lookback中,我使用我们的库分发静态存档框架。似乎当你使用Build& Archive之外的任何东西进行构建时,bitcode实际上并没有发布到我的库中,并且任何在他们的应用程序中与我的库链接并尝试进行构建和编辑的人。启用Bitcode的存档将收到两个警告之一:

At Lookback, I distribute a static archive framework with our library. It seems that when you build with anything but a "Build & Archive", bitcode is not actually emitted into my library, and anyone who links with my library in their app and tries to do a Build & Archive with Bitcode enabled will get one of two warnings:


  • ld:'Lookback(Lookback.o)'确实不包含bitcode。您必须在启用bitcode(Xcode设置ENABLE_BITCODE)的情况下重建它,从供应商处获取更新的库,或禁用此目标的bitcode。(如果使用Xcode 6构建lib)

  • ld:警告:无法生成完整的bitcode包,因为'Lookback(Lookback.o)'仅使用bitcode标记构建。该库必须从启用了bitcode的Xcode存档构建(Xcode设置ENABLE_BITCODE)生成(如果lib是使用Xcode 7和正常的xcodebuild构建的)

  • 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. (if lib is built with 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) (if lib is built with Xcode 7 with a normal xcodebuild)

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

I have a build script that builds a device+simulator universal binary, so I can't use Build & Archive, but rather, I run xcodebuild from commandline from my script. How can I make xcodebuild generate a proper bitcode-enabled library?

推荐答案

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

Bitcode is a compile-time feature (not a link-time feature) which means that every .o file should contain an extra section called __bitcode when built with bitcode. You can confirm whether your binary is bitcode-compatible by running otool -l (my .o or .a file) | grep __LLVM.

当你正常构建时,Xcode会添加构建标志 -fembed-bitcode-marker 到任何clang调用。这似乎是某种'这就是bitcode会去的地方,如果bitcode被启用',并且实际上并没有启用bitcode。

When you build normally, Xcode adds the build flag -fembed-bitcode-marker to any clang invocation. This seems to be some sort of 'this is where bitcode would go, if bitcode was enabled' thing, and doesn't actually enable bitcode.

当你构建和放大器时; Archive,这个标志被 -fembed-bitcode 取代,它确实构建了一个支持Bitcode的二进制文件。

When you "Build & Archive", this flag is replaced by -fembed-bitcode, which really does build a Bitcode-enabled binary.

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

There seems to be two ways to make xcodebuild use -fembed-bitcode:


  • 使用'archive'操作,如 xcodebuild -target LookbackSDK存档而不是 xcodebuild -target LookbackSDK build 。这具有将二进制文件放入Xcode管理器而不是 build / 文件夹的副作用,尽管您可以使用 -exportArchive解决这个问题 - archivePath ./build (感谢 @JensAyton

  • 通过添加带有 OTHER_CFLAGS = - fembed-bitcode的其他C标志强制使用该标志。您的 xcodebuild 调用看起来像 xcodebuild OTHER_CFLAGS = - fembed-bitcode-target LookbackSDK build

  • Use the 'archive' action, as in xcodebuild -target LookbackSDK archive instead of xcodebuild -target LookbackSDK build. This has the side-effect of putting binaries in your Xcode Organizer instead of the build/ folder, though you can work around that by using -exportArchive -archivePath ./build (thanks @JensAyton)
  • Force usage of the flag by adding Other C Flags with OTHER_CFLAGS="-fembed-bitcode". Your xcodebuild invocation would look something like xcodebuild OTHER_CFLAGS="-fembed-bitcode" -target LookbackSDK build.

后者是我选择的,所以我不必更改我的构建系统,但它会为每个文件生成警告,因为现在将 -fembed-bitcode-marker -fembed-bitcode 发送给clang。 Luckilly后者赢了,生成了一个支持Bitcode的库!

The latter is what I chose so that I don't have to change my build system, but it will generate warnings for every file, since now both -fembed-bitcode-marker and -fembed-bitcode are sent to clang. Luckilly the latter wins, generating a Bitcode-enabled library!

  • Apple DevForums: Bitcode and Assembly?
  • SO: iOS library to BitCode

这篇关于如何在启用Bitcode的情况下xcodebuild一个静态库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆