Getting Matlab 2012b to work with XCode 5 (OS X 10.9 Maverick)

Mathworks haven’t issued a patch for 2012b and OS X 10.9 so I ran the 10.9 patch (from and ran

mex -setup

I then modified the file (mex -setup tells you where this is, on my system its

edit ~/.matlab/R2012b/

In the section called

#PATCH: MacOSX10.8

remove the version numbers from CC and CXX and correct the SDKROOT. I also changed the deployment target to 10.9

#PATCH: MacOSX10.8


After a restart, mex worked fine.

OpenCV and Matlab

I’m experimenting with using OpenCV and Matlab and have come across a problem. Matlab (at least on my Mac) loads its own versions of libraries preferentially. This isn’t normally a problem but if your mex code links against a different version you might get a library conflict. One that I have come across several times is Matlab uses an old version of libtiff (it’s used in imread, imwrite etc) and OpenCV uses a newer version. So when I run an OpenCV mex file, Matlab attempts to load the old version for my OpenCV and the mex file crashes.

My first attempt to solve this was to update the Matlabs version of libtiff – it partially worked. My libraries were fine but it broke imread so it wasn’t acceptable. The solution I found when trying the mexopencv wrapper is to preload the up to date libraries when starting Matlab. The command was

DYLD_INSERT_LIBRARIES=/opt/local/lib/libtiff.5.dylib /Applications/Matlab/ &