xcode 如何使用 ENABLE_BITCODE 编译 OpenCV iOS
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/32710440/
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 to compile OpenCV iOS with ENABLE_BITCODE
提问by grapeot
When I tried to compile my XCode project with OpenCV 2.4 iOS using XCode 7 + iOS SDK 9, XCode complained that
当我尝试使用 XCode 7 + iOS SDK 9 使用 OpenCV 2.4 iOS 编译我的 XCode 项目时,XCode 抱怨说
ld: 'opencv2.framework/opencv2(alloc.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. for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
ld: 'opencv2.framework/opencv2(alloc.o)' 不包含位码。您必须在启用位码的情况下重建它(Xcode 设置 ENABLE_BITCODE),从供应商处获取更新的库,或为此目标禁用位码。用于架构 arm64
clang:错误:链接器命令失败,退出代码为 1(使用 -v 查看调用)
and refused to link. After some googling, it turns outto be because Apple added a new feature named Bitcode for app optimization within App Store. While OpenCV iOS binary hasn't been updated to include Bitcode, it cannot pass the link stage.
并拒绝链接。经过一番谷歌搜索,原来是因为苹果在 App Store 中添加了一个名为 Bitcode 的新功能,用于优化应用程序。虽然 OpenCV iOS 二进制文件尚未更新为包含 Bitcode,但它无法通过链接阶段。
Some referencepointed out a temporary solution to disable ENABLE_BITCODE
so the linking could be done without Bitcode. This will prevent the app being compiled for Apple Watches because Bitcode is mandatory for Watch Apps. Therefore my question is, are there some (best easy) ways to compile iOS OpenCV with Bitcode enabled? (better with a download link for compiled framework)
一些参考指出了禁用的临时解决方案,ENABLE_BITCODE
因此可以在没有 Bitcode 的情况下完成链接。这将阻止为 Apple Watch 编译应用程序,因为 Bitcode 对于 Watch Apps 是必需的。因此,我的问题是,是否有一些(最简单的)方法可以在启用 Bitcode 的情况下编译 iOS OpenCV?(最好有编译框架的下载链接)
回答by 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.]
经过一番搜索和试用,我找到了一种使用 Bitcode 从源代码编译 OpenCV iOS 的方法。此处还提供了编译后的二进制文件:[v3.0] [v2.4]。[免责声明:我不对编译后的二进制文件的完整性负责。使用风险自负。]
The steps of compilation is basically the same as the official document, with only one extra step.
编译步骤与官方文档基本一致,仅多出一步。
Download the code with git:
cd ~/<my_working_directory>
git clone https://github.com/Itseez/opencv.git
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
[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]
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.
使用 git 下载代码:
cd ~/<my_working_directory>
git clone https://github.com/Itseez/opencv.git
为 Xcode 创建符号链接,让 OpenCV 构建脚本找到编译器、头文件等。
cd /
sudo ln -s /Applications/Xcode.app/Contents/Developer Developer
【关键步骤】修改编译脚本,增加Bitcode的额外选项:edit
~/<my_working_directory>/opencv/platform/ios/build_framework.py
,找到包含-DCMAKE_C_FLAGS
. 添加标志-fembed-bitcode
. 例如,在我得到的源代码中,它是第 55 行,看起来像"-DCMAKE_C_FLAGS=\"-Wno-implicit-function-declaration -fembed-bitcode\" " +
更改后。[参考]
构建 OpenCV 框架:
cd ~/<my_working_directory>
python opencv/platforms/ios/build_framework.py ios
如果一切正常,几分钟后您将获得
~/<my_working_directory>/ios/opencv2.framework
. 您可以将此框架添加到您的 Xcode 项目中。
P.S. Ask a question, even when you already know the answer is encouraged according to this poston Meta Stackchange.
PS 提出一个问题,即使你已经知道答案是鼓励根据这篇关于 Meta Stackchange 的帖子。
回答by marko
OpenCV is precisely the kind of software (along with audio and video Codecs) that is likely to have hand-rolled ARM NEON optimisations. The documentationsuggests that ~40 functions have had this treatment in OpenCV3.0.
OpenCV 正是一种可能具有手动 ARM NEON 优化的软件(以及音频和视频编解码器)。该文件表明〜40个功能有过OpenCV3.0这种待遇。
If compiling for LLVM bit-code you'll get the generic (less optimised, implemented in C or C++) versions instead.
如果编译 LLVM 位代码,您将获得通用(优化较少,以 C 或 C++ 实现)版本。
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.
Bitcode 的使用是可选的——除非在为 Apple Watch 编译时,很难想象你无论如何都会运行计算复杂的图像处理。如果您要捆绑手表应用程序,请仅覆盖其上的 bitcode 的构建设置。