How to compile OpenCV for iOS7 (arm64)

Posted on

Question :

How to compile OpenCV for iOS7 (arm64)

Compiling Xcode Project fails with following errors:
‘missing required architecture arm64 in file /Users/*/Git/ocr/opencv2.framework/opencv2′

It works well, if i change Architectures(under Build Settings) to (armv7, armv7s) instead of (armv7, armv7s).

How to change the opencv python build script, to add arm64 support to opencv2.framework?

Asked By: TUNER88


Answer #1:

The latest OpenCV iOS framework supports 64 bit by default

It can be downloaded at: OpenCV download page

Answered By: TUNER88

Answer #2:

I modified the following to make it build, though I haven’t got an arm64 iOS device to test at the moment.

Edit: I also had to follow

Assuming “opencv” is the folder containing the opencv source from Github:

in each of gzlib.c, gzread.c, gzwrite.c located in opencv/3rdparty/zlib/ add:

#include <unistd.h>

at the top after the existing include.

In addition open opencv/platforms/ios/cmake/Modules/Platform/iOS.cmake and change line 88 from:

set (CMAKE_OSX_ARCHITECTURES "$(ARCHS_STANDARD_32_BIT)" CACHE string  "Build architecture for iOS")


set (CMAKE_OSX_ARCHITECTURES "$(ARCHS_STANDARD_INCLUDING_64_BIT)" CACHE string  "Build architecture for iOS")

Furthermore change the buildscript at opencv/platforms/ios/ in lines 99 and 100 from:

targets = ["iPhoneOS", "iPhoneOS", "iPhoneSimulator"]
archs = ["armv7", "armv7s", "i386"]


targets = ["iPhoneOS", "iPhoneOS", "iPhoneOS", "iPhoneSimulator", "iPhoneSimulator"]
archs = ["armv7", "armv7s", "arm64", "i386", "x86_64"]

The resulting library will include the following:

$ xcrun -sdk iphoneos lipo -info opencv2
    Architectures in the fat file: opencv2 are: armv7 armv7s i386 x86_64 arm64

Although I have a remaining concern regarding opencv/platforms/ios/cmake/Toolchain-iPhoneOS_Xcode.cmake which defines the size of a data pointer to be 4 in lines 14 and 17.
It should be 8 for 64bit I guess, so as I haven’t tested if the compiled library is working for arm64 I would suggest further investigations at this point if it does not run properly.

Answered By: aha

Answer #3:

micahp’s answer was almost perfect, but missed the simulator version. So modify platforms/ios/ to:

targets = ["iPhoneOS", "iPhoneOS", "iPhoneOS", "iPhoneSimulator", "iPhoneSimulator"]
archs = ["armv7", "armv7s", "arm64", "i386", "x86_64"]

You’ll need to download the command line tools for Xcode 5.0.1 and then run

python opencv/platforms/ios/ ios
Answered By: Jan

Answer #4:

Try to wait a next month. Will release a new XCode with more powerful supporting of 32/64 bit.

Answered By: pommy

Answer #5:

Modify “” to:

def build_framework(srcroot, dstroot):
    "main function to do all the work"

    targets = ["iPhoneOS", "iPhoneOS", "iPhoneOS", "iPhoneSimulator"]
    archs = ["armv7", "armv7s", "arm64", "i386"]
    for i in range(len(targets)):
        build_opencv(srcroot, os.path.join(dstroot, "build"), targets[i], archs[i])

    put_framework_together(srcroot, dstroot)
Answered By: CReaTuS

Answer #6:

@Jan, I followed your instructions, but OpenCV still doesn’t run on arm64. You made such a detailed and wonderful answer – why not check it out on a simulator and see if you can make it run? 🙂

FWIW, I think it might be harder than it seems. On the openCV stackoverflow clone, there’s an indication that this problem might be non-trivial.

Answered By: zerodog

Answer #7:

Instead of using terminal commands given in the opencv installation guide in official website, use the following commands. Worked for me.

cd OpenCV-2.3.1

mkdir build

cd build

cmake -G “Unix Makefiles” ..


sudo make install

Answered By: shmim

Answer #8:

I was having a similar error, but the issue wasn’t related with the arm64 coompilation.fixed adding the framework libc++.dylib

Answered By: Khawar Ali

Leave a Reply

Your email address will not be published. Required fields are marked *