Labels

Linux (6) OpenCV (4) Deep Learning (3) MATLAB (3) Mac OS X (3) Windows (2) C# (1) Node JS (1)

2014年7月26日 星期六

Configure MATLAB MEX compiler on OSX by Using clang/clang++

The MATLAB mex cannot be directly run on OSX, due to the Apple's proprietary C/C++ compiler. Therefore we need to modify mex config file. There are many ways to achieve this. My steps are as following:

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!

沒有留言:

張貼留言