How To Compile OpenCV based programs on Mac OS/X
How to compile C on OS/X ?
- As on Linux, you need to setup the PKG_CONFIG_PATH variable. For example (assuming you are using a sh-based shell, like bash or zsh):
For Bash:
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig export LD_LIBRARY_PATH=/usr
For csh:
setenv PKG_CONFIG_PATH /usr/local/lib/pkgconfig setenv LD_LIBRARY_PATH /usr
You can check that the PKG_CONFIG_PATH is correct by doing either:pkg-config --cflags opencv pkg-config --libs opencv
How to compile and link the sample code on OS/X ?
You can compile and run the sample code from the directory it's installed in (usually /usr/local/share/opencv/samples/c):
g++ -bind_at_load `pkg-config --cflags opencv` morphology.c -o morphology `pkg-config --libs opencv` ./morphology
Using gcc in OS X
I am using OS X 10.5.7. The gcc command I use successfully is:
gcc -o foo foo.c -I/usr/local/include/opencv -L/usr/local/lib -lcxcore -lcv -lml -lhighgui -lcvaux
You probably don't need all of the "-lcxcore -lcv -lml -lhighgui -lcvaux" in the command line. Just the libs that you need to link.