ios 如何在启用 Bitcode 的情况下 xcodebuild 一个静态库?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31486232/
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 do I xcodebuild a static library with Bitcode enabled?
提问by nevyn
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.
Xcode 7 引入了Bitcode,它是某种 LLVM 中间二进制文件,这意味着 Apple 的服务器可以在我不参与的情况下为不同的架构重新编译我的应用程序。
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:
在 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.
(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)
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 构建的)
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?
我有一个构建设备+模拟器通用二进制文件的构建脚本,所以我不能使用构建和存档,而是xcodebuild
从脚本的命令行运行。如何xcodebuild
生成正确的启用位码的库?
回答by nevyn
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
.
Bitcode 是一个编译时特性(不是链接时特性),这意味着每个 .o 文件在使用 bitcode 构建时都应该包含一个名为 __bitcode 的额外部分。您可以通过运行来确认您的二进制文件是否与位码兼容otool -l (my .o or .a file) | grep __LLVM
。
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.
当您正常构建时,Xcode 会将构建标志添加-fembed-bitcode-marker
到任何 clang 调用中。这似乎是某种“如果启用了 bitcode,这就是 bitcode 会去的地方”的事情,并且实际上并没有启用 bitcode。
When you "Build & Archive", this flag is replaced by -fembed-bitcode
, which really does build a Bitcode-enabled binary.
当您“构建和存档”时,此标志被替换为-fembed-bitcode
,它确实构建了启用 Bitcode 的二进制文件。
There seems to be two ways to make xcodebuild
use -fembed-bitcode
:
似乎有两种方法可以xcodebuild
使用-fembed-bitcode
:
- Use the 'archive' action, as in
xcodebuild -target LookbackSDK archive
instead ofxcodebuild -target LookbackSDK build
. This has the side-effect of putting binaries in your Xcode Organizer instead of thebuild/
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"
. Yourxcodebuild
invocation would look something likexcodebuild OTHER_CFLAGS="-fembed-bitcode" -target LookbackSDK build
.
- 使用“归档”操作,
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
.
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!
后者是我选择让我没有改变我的编译系统,但它会为每个文件警告,现在既然都-fembed-bitcode-marker
和-fembed-bitcode
被发送到铛。幸运的是后者获胜,生成了一个支持 Bitcode 的库!
Resources
资源
回答by Aaron Ash
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.
使用 Xcode 8,我无法开始OTHER_CFLAGS="-fembed-bitcode"
工作。was built without full bitcode. All frameworks and dylibs for bitcode must be generated from Xcode Archive or Install build
当我尝试创建包含我的静态框架的应用程序的存档构建时,我一直遇到一些事情。
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 行如下所示(仅供参考):
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
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
回答by Gautam Jain
Once you add bitcode support for the static lib, it won't be compatible with Xcode 6. The app won't archive.
一旦您为静态库添加了位码支持,它将与 Xcode 6 不兼容。该应用程序不会存档。
I would like to clearly mention the setting for bitcode as @nevyn's answer confused me a little.
我想清楚地提到 bitcode 的设置,因为 @nevyn 的回答让我有点困惑。
Go to Build settings, search for "custom compiler flags". Add -fembed-bitcode
. This will build your lib with bitcode.
转到构建设置,搜索“自定义编译器标志”。添加-fembed-bitcode
. 这将使用位码构建您的库。
回答by Oshitha Wimalasuriya
Select project On Build Settings -> Other C flags, set Debug to -fembed-bitcode-marker and Release to -fembed-bitcode
选择项目 On Build Settings -> Other C flags,将 Debug 设置为 -fembed-bitcode-marker 并将 Release 设置为 -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
在 Build Settings 上,单击顶部的 + 号添加名为 BITCODE_GENERATION_MODE 的用户定义的构建设置,并将 Debug 设置为标记,Release 设置为 bitcode
Edit schema as Release Then click the desired library. A file and get the build path. Get the library form Release folder.
Edit schema as Release 然后单击所需的库。一个文件并获取构建路径。获取库表单 Release 文件夹。