Understanding BitCode functionality in iOS development

When the package was tested yesterday, the following error occurred in the Xcode compilation:

Understanding BitCode functionality in iOS development

Error information is given after ld:: bitcode bundle cannot be generated, resulting in a failure to compile.

The same problem was encountered before, when the solution was to shut down the bitcode option in Xcode:

Understanding BitCode functionality in iOS development

So go to BuildOptions and see that the bitcode function is really turned off. Then why is there such a mistake? I thought about it for a long time before I found out the problem.

Extension features are introduced in the new version. In fact, Extension is equivalent to an independent app, but integrated in the original project, sharing a project with the original project. However, their engineering file configuration and compilation configuration are independent of each other. So go to Extension’s BuildOptions and, indeed, forget to turn off the bitcode function when you’re integrated. This will lead to a packing error:

Understanding BitCode functionality in iOS development

Compile the Enable Bitcode function to No and compile successfully!

Since it’s the same with two times, it’s time to figure out what bitcode is.

IOS development of the friends all know, starting from Xcode7, the new project will open the default bitcode settings. But most of the developers are the unexpected bitcode function to pit cause the project to fail to compile, but because these bitcode fail to compile the project have a common point, is linked to the third party binary the library or framework, and the framework or library just does not contain bitcode things (call for something), resulting in the project compiled successfully. So whenever the situation when most people are directly set off bitcode Xcode function, principle all do not produce bitcode. not to get to the bottom of this hidden behind a switch, and I like.

LLVM is currently using the apple compiler tool chain, Bitcode is an intermediate code encoding LLVM compiler, LLVM front end can be understood as programming languages such as C/C++/OC/Swift, LLVM and Hou Duan can be understood as each chip platform assembly instructions or executable machine command data, then BitCode is located in the middle of the two directly compile the code. The working principle of LLVM is responsible for the project source code is translated into Bitcode code, and then depending on the target machine chip platform into a corresponding assembly instruction and translated into machine code. This design can make the LLVM become a compiler framework, the invention of a new language can be an easy job to do in LLVM architecture (front), and support for the new CPU LLVM architecture (Hou Duan) in the following command output, while Bitcode is only an intermediate code not in Ren Heping On the run, but it can be transformed into any supported CPU architecture, including now has not been invented the CPU architecture, is now open Bitcode function to submit a App to the app store, if Apple out of a new mobile phone and CPU is also a new design, in the apple server from the same the App Bitcode began to compile into new executables on CPU, for the new mobile phone users to download and run the App.

Look at the official document
Bitcode is an intermediate explained: representation of a compiled program. Apps you upload to iTunes Connect that contain bitcode will be compiled and linked on the App Store. Including bitcode will allow Apple to re-optimize your app binary in the future without the need to submit a new version of your app to the store.

It is said that bitcode is an intermediate form of code for compiled programs. The program that contains the bitcode configuration will be compiled and linked on the App store. Bitcode allows apple to re optimize the binaries of our programs later on, without requiring us to resubmit a new version to the App store.

Continue to see, in What ‘s, New, in, Xcode-New, Features, in, Xcode,, there is a paragraph as follows description

Bitcode. When you archive for submission to the App Store, Xcode will compile your app into an intermediate representation. The App Store will then compile the bitcode down into the bit executables as necessary. 64 or 32

When we submit a program to App store, Xcode compiles the program into an intermediate form of expression (bitcode). App store then compiles the botcode into an executable 64 bit or 32 bit program.

Bitcode configuration

In the error tip above, we mentioned how to deal with the problems we encountered:

You, must, rebuild, it, with, bitcode, enabled (Xcode, setting, ENABLE_BITCODE), obtain, an, updated, library, from, the, vendor, or, disable, bitcode, for,, this, target., arm64, for, architecture

Either let the third party library support or close the target bitcode option.

In fact, after Xcode 7, when we build a new iOS program, the bitcode option defaults to YES. We can see this setting in the “Build Settings” -&gt, “Enable Bitcode” option.

However, what we need to consider now is three platforms: iOS, Mac, OS, watchOS.

Corresponding to iOS, bitcode is optional.
for watchOS, bitcode is required.
Mac OS does not support bitcode.

As mentioned above, bitcode is an intermediate code. LLVM official documents have introduced this file format, interested can visit LLVM Bitcode File Format.