Saturday, February 7, 2015

Building MEX files in MATLAB 2014B on Ubuntu 14.04

Ubuntu 14.04 by default has the compiler GCC 4.8, but Matlab R2014b .mex files require GCC 4.7.x

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

Install GCC 4.7 and G++ 4.7

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

Copy the mex-options file 
cp /usr/local/MATLAB/R2014b/bin/mexopts.sh ~/.matlab/R2014b/mexopts.sh

Provide read permissions
chmod 644 ~/.matlab/R2013b/mexopts.sh

Make edits
vim ~/.matlab/R2013b/mexopts.sh

Change :
CC=’gcc’ to CC=’gcc-4.7′
CCX=’g++’ to CCX=’g++-4.7′