Cross-compiling OpenCV for iPhone

In Uncategorized on November 24, 2010 at 9:33 pm

If you are here just to cross-compile OpenCV, follow these simple instructions.  The older post is a little more detailed, error-prone, pedantic, and maybe out of date.

If you want to cross-compile OpenCV from source code, you can do by next steps.

  1. Building OpenCV 2.1 requiers CMake. You can easily install it by using MacPorts, or follow the installation instructions at the CMake website.
    % sudo port install cmake
  2. Clone this project from github, then move into the project directory
    % git clone git://github.com/gonzojive/iphone_opencv_test.git
    % cd iphone_opencv_test
  3. Download the source code for OpenCV from Sourceforge. Save OpenCV-2.1.0.tar.bz2 into the project root.
  4. Use the provided Makefile:
    % make

This will extract the downloaded archive, apply a patch to the OpenCV code, generate appropriate cmakefile suport using the opencv_cmake.sh script, and finally make the static libraries for simulator and device.  The libraries will be in the opencv_{device,simulator} directories, and may be linked in XCode etc.

  1. […] Edit November 24, 2010: Building OpenCV […]

  2. Awesome. Just what I was looking for. Just wondering… do you happen to have an updated patch file for 2.2.0 ?

  3. I don’t, but the patch is pretty minor and may work as-is. I’ll give it a shot in the future. Have there been any iPhone-relevant changes in 2.2?

  4. This script is great! It works. I have one more question: how to enable highgui API in the iphone build?

  5. I haven’t tried. I believe highgui has more dependencies, which would require compiling things like libpng and libtiff for iPhone. I have compiled those libraries for iPhone, too, but haven’t needed highgui. let me know if you find additional instructions for highgui, and I can post them here

  6. Hi,
    I hope this web page is still being seen by people that know what they are doing!

    When i run the make command i am getting the following output:-

    if test -d “OpenCV-2.1.0”; \
    then echo “OpenCV-2.1.0” exists, no need to extract; \
    else tar xjf “OpenCV-2.1.0”.tar.bz2; \
    cd “OpenCV-2.1.0”; patch -p1 < ../"OpenCV-2.1.0".patch
    patching file CMakeLists.txt
    patching file src/CMakeLists.txt
    mkdir -p build_simulator; \
    cd build_simulator; \
    ../opencv_cmake.sh Simulator ../"OpenCV-2.1.0"; \
    make -j 4; \
    make install;
    Starting cmake…
    Target SDK = iPhoneSimulator
    iOS SDK Version = 4.1
    iOS Deployment Target = 3.0
    OpenCV Root = ../OpenCV-2.1.0
    OpenCV Install Prefix = /Users/richardfoster/iphone_opencv_test/build_simulator/../opencv_simulator

    — The C compiler identification is GNU
    — The CXX compiler identification is GNU
    — Checking whether C compiler has -isysroot
    — Checking whether C compiler has -isysroot – yes
    — Checking whether C compiler supports OSX deployment target flag
    — Checking whether C compiler supports OSX deployment target flag – yes
    — Check for working C compiler: /Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/gcc
    — Check for working C compiler: /Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/gcc — broken
    CMake Error at /opt/local/share/cmake-2.8/Modules/CMakeTestCCompiler.cmake:52 (MESSAGE):
    The C compiler
    "/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/gcc" is
    not able to compile a simple test program.

    It fails with the following output:

    Change Dir: /Users/richardfoster/iphone_opencv_test/build_simulator/CMakeFiles/CMakeTmp

    Run Build Command:/usr/bin/make "cmTryCompileExec/fast"

    /usr/bin/make -f CMakeFiles/cmTryCompileExec.dir/build.make

    /opt/local/bin/cmake -E cmake_progress_report

    Building C object CMakeFiles/cmTryCompileExec.dir/testCCompiler.c.o

    -mmacosx-version-min="10.6" -o
    CMakeFiles/cmTryCompileExec.dir/testCCompiler.c.o -c

    Linking C executable cmTryCompileExec

    /opt/local/bin/cmake -E cmake_link_script
    CMakeFiles/cmTryCompileExec.dir/link.txt –verbose=1

    -mmacosx-version-min="10.6" -Wl,-search_paths_first
    CMakeFiles/cmTryCompileExec.dir/testCCompiler.c.o -o cmTryCompileExec

    ld: warning: in
    file was built for i386 which is not the architecture being linked (x86_64)

    Undefined symbols:

    "_exit", referenced from:
    start in crt1.10.6.o

    ld: symbol(s) not found

    collect2: ld returned 1 exit status

    make[2]: *** [cmTryCompileExec] Error 1

    make[1]: *** [cmTryCompileExec/fast] Error 2

    CMake will not be able to correctly generate this project.
    Call Stack (most recent call first):
    CMakeLists.txt:39 (project)

    — Configuring incomplete, errors occurred!
    make[1]: *** No targets specified and no makefile found. Stop.
    make[1]: *** No rule to make target `install'. Stop.
    make: *** [opencv-simulator] Error 2

    Is there anybody that knows what the problem could be here. Could it be because the version of cmake I have is for the wrong operation system?


  7. I’m having the same issue as Richard. Any suggestions? /Developer has XCode 3.2.6 installed.

  8. I have the same error with Richard, please suggest a solution, thank you!

  9. Hi –
    I’m wondering if anyone resolved the issue Richard or Michael was having?

  10. I’m having the same issue as Richard. Any suggestions?

  11. Look at the yoshimasa niwa http://niw.at/articles/2009/03/14/using-opencv-on-iphone/en explaining how to configure version 2.2.0 with Xcode 4 and iOS SDK 4.3

  12. CMake is available as a dmg pkg installer for OSX Leopard and later, here:


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: