本文介绍了-fembed-bitcode`和BITCODE_GENERATION_MODE有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在更新静态库以支持位码,从我的研究中,我发现了两种实现方法:

I've been updating a static library to support bitcode, and from my research I found two ways to achieve that:

  • fembed-bitcode标志添加到我的项目构建设置"中的其他C标志"选项中()
  • 添加将键BITCODE_GENERATION_MODE设置为bitcode的用户定义设置(链接)
  • Adding the fembed-bitcode flag to the Other C flags option in my project Build Settings (link)
  • Adding a User-defined Setting with the key BITCODE_GENERATION_MODE set to bitcode (link)

这两个选项之间有区别吗?

我注意到的唯一区别是,通过使用fembed-bitcode,将为iphonesimulator生成的静态库将启用完整的位代码(在我的情况下,二进制大小从5MB更改为13MB,我可以使用otool),它的用法似乎没有任何区别.

The only difference I noted is that by using fembed-bitcode, the resulting static library for iphonesimulator will be built with full bitcode enabled (in my case, binary size changes from 5MB to 13MB, and I can check bitcode support using otool), which doesn't seem to make any difference in its usage.

推荐答案

正常使用ENABLE_BITCODE=YES生成库时,Xcode将生成标志-fembed-bitcode-marker添加到任何clang调用中,在最终o文件.

When you build the library normally, with ENABLE_BITCODE=YES, Xcode adds the build flag -fembed-bitcode-marker to any clang invocation, placing an "empty" bitcode in the final o file.

因此,如果您在构建阶段使用了编译操作,它将看起来像这样:

So, if you look to the compile action in the build phase, it will look something like:

这对于构建操作(独立于目标)是正确的.

This is true to the build action (independent of the target).

当您Build & Archive时,-fembed标志将替换为-fembed-bitcode,这实际上会构建一个启用了位码的二进制文件:

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


鉴于,如果将-fembed-bitcode标志添加到Other C标志,则将在编译期间向编译器发送两个标志.使用链接到另一个项目的库时,您可能会收到一些警告,它可能会保持沉默.但是,您需要检查您是否获得了预期的行为. :)

Given that, if you add the -fembed-bitcode flag to the Other C flags, you will be sending two flags to the compiler during the compile time. It maybe silence some warnings that you can receive when using the library linked on another project. But, you need to check if you get the expected behavior. :)

(当我在其他C标志上使用-fembed-bitcode测试时,Xcode给出了警告clang: warning: argument unused during compilation: '-fembed-bitcode-marker')

(When I tested using the -fembed-bitcode on the Other C flags, Xcode gave the warning clang: warning: argument unused during compilation: '-fembed-bitcode-marker')


另一方面,

如果在User-defined Setting上设置了BITCODE_GENERATION_MODE=bitcode,则即使在构建阶段,也将使用标志-fembed-bitcode来编译文件.

If you set BITCODE_GENERATION_MODE=bitcode on your User-defined Setting, even during the build phase, the files will be compiled using the flag -fembed-bitcode.

而且,如果设置BITCODE_GENERATION_MODE=marker,则将使用标志-fembed-bitcode-marker编译文件,而与操作阶段无关.

And, if you set BITCODE_GENERATION_MODE=marker, the files will be compiled using the flag -fembed-bitcode-marker, independent of the action phase.

因此,如果要对每个操作(构建和存档)启用位码,则更好的方法是使用BITCODE_GENERATION_MODE设置.

So, if you want to enable the bitcode to every action (build and archive), the better way to do so is using the BITCODE_GENERATION_MODE setting.


  • How do I xcodebuild a static library with Bitcode enabled?
  • Apple DevForums: Bitcode and Assembly?
  • SO: iOS library to BitCode

这篇关于-fembed-bitcode`和BITCODE_GENERATION_MODE有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-10 21:23