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
EDIT: successfully tested with opencv 2.4.5 on mac os x mountain lion 10.8.3 and Xcode 4.5
Having the right tools
- download opencv-unix from http://sourceforge.net/projects/opencvlibrary/files/ and untar it wherever
- download cmake .dmg from http://www.cmake.org/cmake/resources/software.html and install it
- i am assuming you have xcode 4.6 on os x lion which includes the ios sdk 6.1
- go to xcode preferences to download and install the Command Line Tools so you have g++ etc.
Use cmake to compile opencv
- go to the extracted opencv folder
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
from the build folder, go to bin/ and run one of the tests
./opencv-test-photo
Create your own c++ opencv xcode project
- fire up xcode and create a new xcode project
- select Command Line Tool for the type of project under os x
- open your project's build settings
- under Architectures, set Architecture to 64-bit intel. also set Valid Architectures to x86_64
- under Build Options, set Compiler for C/C++ to Default Compiler
- under Search Paths, set Header Search Paths to /usr/local/include
- also under Search Paths, set Library Search Paths to /usr/local/lib
- under Apple LLVM compiler 4.2 - Language set C++ Standard Library to libstd++ (With OpenCV 2.4.6, Xcode 5, LLVM 5.0, and 10.8.5, set both language dialect and std library to "Compiler Default" instead)
Add the compiled opencv libraries to your project
- go the the Build Phases tab next to Build Settings tab you were in
- inside Link Binary With Libraries, click on the + sign and choose Add Other
- hit the front slash / on your keyboard and enter /usr/local/lib
- hit enter and select the libraries you want to use in your project
- make sure you always select libopencv_core.2.4.4.dylib
- hit enter and you will see the selected dylibs under your project
write some code
- first lets organize the files, right click on your project blueprint icon and select New Group
- name the new group opencv or whatever
- drag the dylibs and drop them in that group
- open main.cpp
- copy code from any of the sample tests that came with opencv and paste it here
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.