1. Run "mex -setup" in MATLAB, you will see the options:
The options files available for mex are:
1: /Applications/MATLAB_R2010a.app/bin/gccopts.sh :
Template Options file for building gcc MEX-files
2: /Applications/MATLAB_R2010a.app/bin/mexopts.sh :
Template Options file for building MEX-files via the system ANSI compiler'
2. Select "mexopts.sh" as template. MATLAB will create a copy at your home folder:
"~/MATLAB/R2011b/mexopts.h"
3. Open "~/MATLAB/R2011b/mexopts.h" and find string "maci64", change CC='gcc' to CC='clang', and CXX='g++' to CXX='clang++':
4. MATLAB MEX will complain that "error: unknown type name 'char16_t' typedef char16_t CHAR16_T;". To solve this issue, add the definition in preprocessor flag "-Dchar16_t=uint16_T" :
COPTIMFLAGS='-O2 -DNDEBUG -Dchar16_t=uint16_T'
4. Restart MATLAB, MEX should work fine!