Matlab R2013b C++ MEX on Ubuntu 14.04

Ubuntu 14.04 comes with GCC 4.8, but Matlab R2013b wants GCC 4.8.
The error you will get includes.
Warning: You are using gcc version ‘4.8.2’. The version of gcc is not supported.

Note that Matlab R2014a uses a new system for MEX configuration. You should not use this process for R2014a and newer. For Matlab R2014a I don’t have a solution for specifying gcc-4.7 besides taking the output of mex -v and editing the commands to use gcc-4.7 manually. Yikes!

This example is for R2013b and OLDER

sudo apt-get install gcc-4.7 g++-4.7

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

chmod 644 ~/.matlab/R2013b/

nano ~/.matlab/R2013b/
there will be one instance each of:
CC=’gcc’ change to –> CC=’gcc-4.7′
CCX=’g++’ change to –> CCX=’g++-4.7′
5) restart Matlab

Matlab R2013a: C++ MEX on Ubuntu 14.04 64-bit

Note: the way Mex setup works has changed in R2014a and newer. This is for older version of Matlab R2013 and older


Ubuntu 14.04 comes with GCC 4.8, but Matlab R2013a gives warnings about needing GCC 4.4 if using MEX features.

(1) Packages to install (synaptic or apt-get)


(2) in Matlab, type mex -setup and press 1 to copy the to your ~/.matlab/R2013a/

(3) sudo chmod 644 ~/.matlab/R2013a/
(allows you to edit this file)

(3) gedit
and change:


Also to save yourself grief when you’re using a modern C++ syntax file (especially if you get errors like
error: expected expression before ‘/’ token
then make this additional changes:


(4) Save/exit gedit and restart Matlab. You should now be able to use MEX in Matlab R2013a under Ubuntu 14.04.