How to compile OpenCV iOS with ENABLE_BITCODE

夙愿已清 提交于 2019-11-30 03:28:09
grapeot

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!