How to compile OpenCV iOS with ENABLE_BITCODE How to compile OpenCV iOS with ENABLE_BITCODE xcode xcode

How to compile OpenCV iOS with ENABLE_BITCODE


After some search and trial, I figured out a way to compile OpenCV iOS from the source with Bitcode. A compiled binary is also provided here: [v3.0] [v2.4]. [Disclaimer: I am not responsible for the integrity of the compiled binary. Use at your own risk.]

The steps of compilation is basically the same as the official document, with only one extra step.

  1. Download the code with git:

    cd ~/<my_working_directory>

    git clone https://github.com/Itseez/opencv.git

  2. Make symbolic link for Xcode to let OpenCV build scripts find the compiler, header files etc.

    cd /

    sudo ln -s /Applications/Xcode.app/Contents/Developer Developer

  3. [Key Step] Change the compilation script to add the extra option for Bitcode: edit ~/<my_working_directory>/opencv/platform/ios/build_framework.py, and locate the line containing -DCMAKE_C_FLAGS. Add a flag of -fembed-bitcode. For example, in the source I got, it's line 55, and will look like

    "-DCMAKE_C_FLAGS=\"-Wno-implicit-function-declaration -fembed-bitcode\" " +

    after the change. [ref]

  4. Build OpenCV framework:

    cd ~/<my_working_directory>

    python opencv/platforms/ios/build_framework.py ios

    If everything’s fine, a few minutes later you will get ~/<my_working_directory>/ios/opencv2.framework. You can add this framework to your Xcode projects.

P.S. Ask a question, even when you already know the answer is encouraged according to this post on Meta Stackchange.


OpenCV is precisely the kind of software (along with audio and video Codecs) that is likely to have hand-rolled ARM NEON optimisations. The documentation suggests that ~40 functions have had this treatment in OpenCV3.0.

If compiling for LLVM bit-code you'll get the generic (less optimised, implemented in C or C++) versions instead.

Use of Bitcode is optional - except when compiling for Apple watch, where it's hard to imagine you'd run computationally complex image processing anyway. If you're bundling a watch app, override the build setting for bitcode on it only.