# Configuring MATLAB to work with XCode 6 on Yosemite

Oct 28, 2014

After I upgraded my Mac to Yosemite (10.10), I had a lot of trouble to get MATLAB 2013a working properly. First, I started getting a NullPointerException from Java when trying to start it. Turns out this was a problem with some Java classes used for drawing MATLAB's GUI and Mathworks released some patches for MATLAB versions from R2012b to R2014a (the bug was fixed in R2014b).

Unfortunately, that was not the only issue. Since I also upgraded to XCode 6, I was not able to compile MEX files anymore. I checked the system requirements at the Mathworks website and it states that R2013a and R2013b support XCode 4.3 or higher, and R2014a supports either 4.6+ or 5.0. From my previous experience, I know sometimes these are "soft" requirements and I managed to make MATLAB work with unsupported compilers (like different versions of Visual Studio on Windows, or different versions of GCC on Linux). However, on a Mac the command mex -setup only gives you an option to keep your current compiler configuration or copy the default file to your home folder. Here's what I did to make MATLAB work with XCode 6:

1. Run mex -setup and ask it to copy the default mexopts.sh to my home folder.
2. Edit /Users/myusername/.matlab/R2013a/mexopts.sh, replacing all instances of 10.8 to 10.10 in the section corresponding to Mac 64 bits (i.e., everything after the line maci64) and the end of the file).

After doing this, calling mex worked, but I was still not able to compile my MEX files. The error message I got was the following:

error: unknown type name 'char16_t'
typedef char16_t CHAR16_T;.


Turns out the compiler that ships with XCode 6 (Clang) does not set char16_t, as explained in this helpful Stack Overflow post. Instead of having to remember to set this to UINT16_T every time I compile a MEX file or editing the source, I decided to add this to my mexopts.sh file, which leads us to the third and final step:

1. Replace the line that reads CFLAGS="$CFLAGS -fexceptions" by CFLAGS="$CFLAGS -fexceptions -Dchar16_t=UINT16_T"`.

After adding this, MATLAB happily compiled all of the MEX files I tested, even some I had generated with MATLAB Coder.

This entry was tagged as development