How to compile MATLAB MEX files (based on OpenCV library) on Mac OS X Tiger - a short guide
I was trying to compile the fast Normalized Cross-correlation function from Daniel Eaton, when I encountered compilation errors on my PowerMac G5. It took me some time to figure out a solution, so I thought it might be useful to other people who want to use Intel s Open Computer Vision library in MATLAB on Mac OS X Tiger.
- Follow Christoph Seibert’s guide to compile OpenCV on Mac OS X Tiger. You will need Fink installed (use FinkCommander), as well as Apple XCode and X11.
- Open an X11 Terminal window and type in the following command to set up the environment for pkg-config.
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
Or you can add this line to your .bash_profile file. - Following the above command, start MATLAB by typing:
/Application/MATLAB71/bin/matlab
(use your own version of MATLAB, instead of 7.1 here) - In MATLAB command window, type in
mex -setup
and choose the default gcc option (# 2). - Open a new Terminal window and modify the matlab mexopts.sh file (~/.matlab/R14SP3/mexopts.sh for example). Now open the file with your favorite text editor (vi or pico) and find the section starting with
mac)
#-------------------------
CC='gcc-3.3'
- replace the CC line with the following line and save the file.
CC='gcc-3.3 -bind_at_load `pkg-config --cflags opencv` `pkg-config --libs opencv`' - Okay, now you can go ahead and compile the MEX file, by using the “mex” command in MATLAB. For example:
mex mycode.cpp
Have fun!