1

I followed this tutorial : http://tilomitra.com/opencv-on-mac-osx/ to compile OpenCV for Mac OSX in order to use it in XCode 3.2.3

I had no error when compiling openCV. But in XCode I get file was built for unsupported file format which is not the architecture being linked (i386) for each dylib and Symbols not found after.

Any clue ?

Matthieu Riegler
  • 31,918
  • 20
  • 95
  • 134
  • 1
    Related: http://stackoverflow.com/questions/10183053/file-was-built-for-unsupported-file-format-which-is-not-the-architecture-being-l – Ian Medeiros Feb 19 '13 at 17:03

1 Answers1

0

steps to compile and run c++ opencv 2.4.4 on mac os x lion 10.7.5 with cmake 2.8.10 and xcode 4.6.1

Having the right tools

  1. download opencv-unix from http://sourceforge.net/projects/opencvlibrary/files/ and untar it wherever
  2. download cmake .dmg from http://www.cmake.org/cmake/resources/software.html and install it
  3. i am assuming you have xcode 4.6 on os x lion which includes the ios sdk 6.1
  4. go to xcode preferences to download and install the Command Line Tools so you have g++ etc.

Use cmake to compile opencv

  1. go to the extracted opencv folder
  2. create a build directory

    mkdir build
    cd build
    cmake -D WITH_TBB=OFF -D BUILD_NEW_PYTHON_SUPPORT=OFF -D BUILD_FAT_JAVA_LIB=OFF -D BUILD_TBB=OFF -D BUILD_EXAMPLES=ON -D CMAKE_CXX_COMPILER=g++ CMAKE_CC_COMPILER=gcc -D CMAKE_OSX_ARCHITECTURES=x86_64 -D BUILD_opencv_java=OFF -G "Unix Makefiles" ..
    make -j8
    sudo make install
    
  3. from the build folder, go to bin/ and run one of the tests

    ./opencv_test_stitching
    

Create your own c++ opencv xcode project

  1. fire up xcode and create a new xcode project
  2. select Command Line Tool for the type of project under os x
  3. open your project's build settings
  4. under Architectures, set Architecture to 64-bit intel. also set Valid Architectures to x86_64
  5. under Build Options, set Compiler for C/C++ to Default Compiler
  6. under Search Paths, set Header Search Paths to /usr/local/include
  7. also under Search Paths, set Library Search Paths to /usr/local/lib
  8. under Apple LLVM compiler 4.2 - Language set C++ Standard Library to libstd++

Add the compiled opencv libraries to your project

  1. go to the Build Phases tab next to Build Settings tab you were in
  2. inside Link Binary With Libraries, click on the + sign and choose Add Other
  3. hit the front slash / on your keyboard and enter /usr/local/lib
  4. hit enter and select the libraries you want to use in your project
  5. make sure you always select libopencv_core.2.4.4.dylib
  6. hit enter and you will see the selected dylibs under your project

write some code

  1. first lets organize the files, right click on your project blueprint icon and select New Group
  2. name the new group opencv or whatever
  3. drag the dylibs and drop them in that group
  4. open main.cpp
  5. copy code from any of the sample tests that came with opencv and paste it here
  6. make sure all the required dylibs are added, for example, if you copied the opencv_test_stitching.cpp code into main.cpp, you will need to add the following libraries in the previous steps libopencv_core.2.4.4.dylib libopencv_highgui.2.4.4.dylib libopencv_stitching.2.4.4.dylib

Cheers.

  • You've posted the identical answer to three separate questions. Can you explain in each answer how it solves the particular problem. – ChrisF Mar 27 '13 at 22:11
  • the answer covers all the steps required for compiling and using opencv on a mac. I thought it's better than posting a half assed answer, which was a problem for me trying to compile and run opencv based on the answers here. in this particular case, since compiling worked fine, start at **Create your own c++ opencv xcode project** and follow the steps there. –  Mar 28 '13 at 17:02