Download OpenCV 2.3.1a and unpack it:
curl -L -O http://downloads.sourceforge.net/project/opencvlibrary/opencv-unix/2.3.1/OpenCV-2.3.1a.tar.bz2 tar xzvpf OpenCV-2.3.1a.tar.bz2
Then configure and compile it:
cd OpenCV-2.3.1 mkdir build cd build cmake -G "Unix Makefiles" .. make sudo make install
You can use different options when executing cmake
:
- -D BUILD_EXAMPLES=ON -> Compile example programs.
- -D BUILD_TESTS=OFF -> Don’t compile tests.
- -D BUILD_NEW_PYTHON_SUPPORT=OFF -> Don’t compile new Python support.
- -D WITH_CARBON=ON -> (mostly for Leopard and below) To use Carbon instead of Cocoa (since version r2909).
- -D WITH_QUICKTIME=ON -> (mostly for Leopard and below) To use QuickTime for the I/O of Video instead of QTKit (since version r2924). If you use Snow Leopard and need Carbon and QuickTime, you must also specify -D CMAKE_OSX_ARCHITECTURES=i386, -D CMAKE_C_FLAGS=-m32 and -D CMAKE_CXX_FLAGS=-m32.
If you don’t have cmake installed download a “binary distribution” from cmake.org. For example http://www.cmake.org/files/v2.8/cmake-2.8.7-Darwin64-universal.dmg.
You can compile OpenCV for an specific architecture using CMAKE_OSX_ARCHITECTURES
with those values:
i386 x86_64 ppc ppc64
For example:
cmake -G "Unix Makefiles" -D CMAKE_OSX_ARCHITECTURES=i386 ..
To create a “universal build” use both i386 and ppc:
cmake -G "Unix Makefiles" -D CMAKE_OSX_ARCHITECTURES=i386 ppc ..
If you want to compile for a 32 bit architecture is mandatory to add -m32
to C
and CXX
flags. If you don’t add it you could end up with this warning:
created and used with differing settings of '-m32'
To solve this use -m32
option in CMAKE_C_FLAGS
and CMAKE_CXX_FLAGS
:
cmake -G "Unix Makefiles" -D CMAKE_OSX_ARCHITECTURES=i386 -D CMAKE_C_FLAGS=-m32 -D CMAKE_CXX_FLAGS=-m32 ..
cmake -G “Unix Makefiles” -D CMAKE_OSX_ARCHITECTURES=i386 ..
results an error :
” CMake Error at CMakeLists.txt:69 (message):
CMake fails to deterimine the bitness of target platform.
Please check your CMake and compiler installation. If you are crosscompiling then ensure that your CMake toolchain file correctly sets the compiler details. ”
I’m using opencv-2.4.2
Any idea ?!
Use this option to specify 32 bits:
-D CMAKE_C_FLAGS=-m32 -D CMAKE_CXX_FLAGS=-m32
Aha, thank you
Another question, I’m using opencv-2.4.2 for IOS
so can I write:
“cmake -G “Unix Makefiles” -D CMAKE_IOS_ARCHITECTURES=armv7 ..”
it also generated the same error !
any idea?
I think OpenCV 2.4.2 has a different way to compile for iOS. You can also download a prebuilt framework here http://sourceforge.net/projects/opencvlibrary/files/opencv-ios/2.4.2/opencv2.framework.zip/download.
Yes, I finally (after 2 weeks) realized that using this prebuilt framework is the safe way.
Just a hint to others.
Thank you