Compiling OpenCV 2.0 on Snow Leopard
Just a quick info-push to the net. I’ve tried for a while to compile OpenCV 2.0 on Snow Leopard, which always failed with problems in Carbon and Quicktime support of highgui, like so:
opencv/src/highgui/window_carbon.cpp: In function ‘void icvDrawImage(CvWindow*)’:
opencv/src/highgui/window_carbon.cpp:222: error: ‘GetWindowPortBounds’ was not declared in this scope
opencv/src/highgui/window_carbon.cpp:238: error: ‘SetPortWindowPort’ was not declared in this scope
This was using CMake to generate Unix Makefiles to build OpenCV. The solution is simple: Just build it via Xcode! Using
ccmake -G Xcode
on the command line, you can create Xcode project files that will work just fine with Xcode 3.2.
I’ve put an installer here. Requires Snow Leopard and installs to /usr.
[Edit] Of course, this builds for x386 architecture and not x86_64, i.e. the libraries you get are 32bit. This is necessary because Carbon is 32bit. If you need 64bit, you’re out of luck with Carbon.
[Edit] This means you have to add “-arch i386″ to your compile flags.
Thanks for providing this installer. For some reason, the installed files were placed in /usr/share/opencv and /usr/include/opencv.
Does this also install the python wrappers? The only python files I found were example scripts.
Hmm. I must admit I didn’t try the installer itself — I built the “INSTALL” target in Xcode, which put everything into /Developer/Libraries, and afterwards built the “package” target which built the installer. Strange that the installer puts things in a different place; probably a bug in the OpenCV build scripts. I’ll adapt the blog text.
Also, I didn’t explicitly do anything about Python, as I’m not using it for CV projects. Sorry.
Hey
I have installed the libs via your installer.
When I try to compile a simple webcam viewer on 10.6 I get this error:
g++ -o “tess” ./src/tess.o -lcxcore -lcv -lml -lhighgui -lcvaux
ld: warning: in /usr/lib/libcxcore.dylib, file is not of required architecture
ld: warning: in /usr/lib/libcv.dylib, file is not of required architecture
ld: warning: in /usr/lib/libml.dylib, file is not of required architecture
ld: warning: in /usr/lib/libhighgui.dylib, file is not of required architecture
ld: warning: in /usr/lib/libcvaux.dylib, file is not of required architecture
Undefined symbols:
“_cvCreateCameraCapture”, referenced from:
_main in tess.o
“_cvNamedWindow”, referenced from:
_main in tess.o
“_cvShowImage”, referenced from:
_main in tess.o
“_cvQueryFrame”, referenced from:
_main in tess.o
“_cvDestroyWindow”, referenced from:
_main in tess.o
“_cvReleaseCapture”, referenced from:
_main in tess.o
“_cvWaitKey”, referenced from:
_main in tess.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
make: *** [tess] Error 1
@Marc: What architecture are you compiling for? Try adding “-arch i386″ to your compile flags. Works for me.
thanks for your quick reply.
When I add the flag I get the following:
Building target: tess
Invoking: MacOS X C++ Linker
g++ -arch i386 -o “tess” ./src/tess.o -lcxcore -lcv -lml -lhighgui -lcvaux
ld: warning: in ./src/tess.o, file is not of required architecture
Undefined symbols:
“_main”, referenced from:
start in crt1.10.6.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
make: *** [tess] Error 1
Yes. You need to compile your main program with “-arch i386″ as well. Duh
Thanks for this !
I wasn’t able to locate the dylibs after building it using XCode but your installer worked.
Ok… I can’t compile a simple helloworld program.
I’m compiling from command line :
g++ helloworld.cpp -o hello-world -I/usr/include/opencv -L/usr/lib -lm -lcv -lhighgui -lcvaux -arch i386
and I get :
Undefined symbols:
“_cvReleaseImage”, referenced from:
_main in ccGGqOY8.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
I fixed it by adding ” -lcxcore ” to the linker settings !
Hi,
how i can run make install after?? i need to put it to custom location. There is no other way to set architecture ?? through cmake or ./configure ?? I indeed suceed to built is but i’m not sure if cuicktime is working good i tried an copen cv example and i have a carbon window camera is initialized (the green diode is on) however program crashes after without any message
ok i found the way
CXXFLAGS=”-m32″ LDFLAGS=”-m32″ ./configure –prefix=/xxx works for opencv2.0 on os x 10.6
Good one! Thanks for figuring that out!
Nice job!
How can I create an Xcode project to be able to debug the code?
I am now compiling just as guisim posted:
g++ helloworld.cpp -o hello-world -I/usr/include/opencv -L/usr/lib -lm -lcv -lhighgui -lcvaux -arch i386 -lcxcore
Thanks in advance.
I did the following:
That did the job for me.
Hi,
After I build opencv libraries from Xcode, I got error in installing.
Definitely it is because access problem.
Is there a way to run install in Xcode just like we do this in command line?
Thank
So I downloaded OpenCV 2.0 and did:
$ mkdir build
$ cd build
$ ccmake -G Xcode ../
Then I opened the Xcode project generated and built it successfully.
What next? Running make or make install wont work ofc.
Thanks for the tutorial!
@Blazz Well either build the “install” target in Xcode (of course, you need write access to the place you’ve specified as install path when generating the Xcode project file in CMake).
Or build the “package” target and then install the resulting package with MacOS X’s installer.
Or just download the installer I provided.
I did try downloading your installer but I’m having some issues. For starters when I set the library flags on Xcode it’s not finding the libraries, so I wrote the complete path to each library needed. When I finally got it to work when my simple app runs I get the following warning after which my program crashes:
warning: Could not find object file “/Users/bjoern/opencvlibrary/trunk/opencv/3rdparty/lib/Debug/libopencv_lapack.a(slasd5.o)” – no debug information available for “/Users/bjoern/opencvlibrary/trunk/opencv/3rdparty/lapack/slasd5.c”.
So I though it was better for me to compile the code on my Mac and install it
I’m trying that right now, looking good so far!
@bjoern
I was using a python wrapper on top of your provided install:
arch -i386 python capture-cam.py
But receive this error:
OSError: dlopen(/usr/lib/libcxcore.dylib, 6): no suitable image found. Did find:
/usr/lib/libcxcore.dylib: mach-o, but wrong architecture
Any ideas?
Well, I’ve never used OpenCV with python, sorry. But:
slytherin:~ bjoern$ which python
/usr/bin/python
slytherin:~ bjoern$ arch -i386 python
Python 2.6.1 (r261:67515, Jul 7 2009, 23:51:51)
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import platform
>>> print platform.machine(), platform.architecture()
i386 ('64bit', '')
This suggests that the preinstalled python on Snow Leopard is 64-bit only, and the OpenCV binaries are 32-bit.
I’ve heard there are some wildlife groups trying to get Apple to do more stuff with the actual S.L.’s lol. I don’t know- people are saying it’s good PR for Apple- they should jump on that.
Thanks for the info. I was able to use make with Snow Leopard and OpenCV from the trunk by setting the following using ccmake
CMAKE_OSX_ARCHITECTURES = i386
CMAKE_CXX_COMPILER = /usr/bin/g++-4.0
CMAKE_C_COMPILER = /usr/bin/gcc-4.0
I wanted to also link with gsl, which required that I install the i386 version of gsl.
sudo port install gsl +universal
Hi,
I am new to Mac OS X.
I have a snow leopard 10.0.6.2
I tried both your install script (dmg file) and other instructions.
It didn’t work! I also need video.
Can you please write instructions more clearly for snow leopard(explain each step from scratch)?
Thanks…
Please can you provide also a version compiled with –with-ffmpeg flag instead of quicktime?
Ps. Do you know if the quicktime codec is unable to read an mjpeg streaming from an ip camera?
Err, no. Sorry.
It’s not so hard to compile the thing yourself, though.
Hi,
Thanks for sharing your experience.
I have build opencv for -i386 with xcode, whats next? Do i have to add someting to: DYLD_LIBRARY_PATH? If yes, which directories?
At the moment the 3 header files are not found, compiling a new test project( with highgui.h etc. included)
@mc_plectrum
I have now sucessfully build the install target, but the header files cannot be found. What should i do?
[SOLVED]
this post: “jdiamond
Dec 17, 2008, 11:40 AM
Thanks so much for your help! Thanks to your link, I found that if you expand an individual target under the Targets list in the project, you see a folder called “Link Binary With Libraries”, which you can right click on and then choose “add existing file.”
finally solved it…
this is what i have done before: http://tech.groups.yahoo.com/group/OpenCV/message/68092
Thanks, I got compiler successfully on Snow Leopard.
The new python wrappers should be available as “import cv” but the current 2.0.0a build does not create them. How can I build opencv 2.0.0 with the new wrappers? I’ve tried Bjorn’s install, also the ccmake install method on WillowGarage, but I can’t find evidence that it creates them (I could move them to the right place if I could find them).
@bjoern
python under SL is an universal binary with 3 architectures
file /usr/bin/python
/usr/bin/python: Mach-O universal binary with 3 architectures
/usr/bin/python (for architecture x86_64): Mach-O 64-bit executable x86_64
/usr/bin/python (for architecture i386): Mach-O executable i386
/usr/bin/python (for architecture ppc7400): Mach-O executable ppc
The way you have tested gives the running architecture… which is of course the one of your hardware…
To compile OpenCV 2.0 with Python support under Snow Leopard, you need to do the following changes to the Xcode project generated by cmake -G Xcode :
1. you have to add the Python framework to the cvpy target, and thus add a “Link binary with Libraries” step to this target
2. you have to remove of the same target:
a. the “-framework Python” from the “Other Linker Flags”
b. the “python” from the “Header Search Path”
3. you need to change the first line of cv.ccp from
#include <Python.h" to #include
and then compiling with current SDK set to 10.6 works.
Good one, thanks for the info. As I said, I never did anything with Python and OpenCV… that was the main content of that comment.
Hi, I have Mac OS X 10.6.2, and have the need to use Quicktime and Carbon.
I used to build Xcode Framework with the obsoleted build_framework.sh, which had been removed since r2528.
Now I’m trying to build r2641 with CMake, and your hint made me almost done!
BTW, I turned off “WITH_1394, WITH_FFMPEG, WITH_UNICAP” in CMake GUI.
“ALL_BUILD” target worked OK (Well, there’s a C++ bug in acameracalibration_artificial.cpp, line 58 that needs to be changed into “typename” Mat_::const_iterator pos = mat.begin(), …
However, “install” target gave me this error:
/opt/local/bin/cmake -DBUILD_TYPE=Debug -P cmake_install.cmake
– Install configuration: “Debug”
– Installing: /usr/local/share/opencv/OpenCVConfig.cmake
CMake Error at cmake_install.cmake:31 (FILE):
file INSTALL cannot copy file
“/PATH_TO_OPENCV/opencv/unix-install/OpenCVConfig.cmake”
to “/usr/local/share/opencv/OpenCVConfig.cmake”.
make: *** [install_buildpart_0] Error 1
Command /bin/sh failed with exit code 2
Again it seemed like an “administrative privilege” problem. I encountered that once and did manual “mkdir” to fix it, but this time I had no idea. Can you tell me how to fix it? (My account IS an administrator)
And could you please describe again, after “install”, where are those build files? And how do I “use” the library? Like the “PATH_TO_CV_LIBRARIES” in comment #14.
Thanks in advance!