Matlab R2013b C++ MEX on Ubuntu

It’s better to upgrade Matlab to a current version instead of the procedure below. This procedure is for Matlab ≤ R2014a. Matlab ≥ R2014a uses a new system for MEX configuration.


Matlab R2013b wants GCC 4.7, so with more modern Linux systems, errors may occur like:

Warning: You are using gcc version '4.8.2'. The version of gcc is not supported.

http://www.mathworks.com/matlabcentral/answers/67521-32bit-and-64bit-compilations#comment_216789

http://www.mathworks.com/help/matlab/release-notes.html

Fix

This example is for Matlab ≤ R2013b. Do not use this process for Matlab ≥ R2014a.

apt install gcc-4.7 g++-4.7

cp /usr/local/MATLAB/R2013b/bin/mexopts.sh ~/.matlab/R2013b/mexopts.sh

chmod 644 ~/.matlab/R2013b/mexopts.sh

in ~/.matlab/R2013b/mexopts.sh change to one instance each of:

CC='gcc-4.7'

CCX='g++-4.7'