Matlab R2013a: MEX on Ubuntu 13.04 64-bit

Ubuntu 13.04 comes with GCC 4.7, but Matlab R2013a requires 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 13.04.


Natael posted on July 31, 2013 at 05:41

Hi, thanks for the 13.04-related explanation.
How about gfortran ? supported version 4.3 is not in the synaptic packages anymore, but i’d like to have a fully supported setup, i’m having some trouble with compiling so gfortran functions and their gateways with gfortran 4.7. Any hint on what/how i should do ? Thanks

mhirsch posted on July 31, 2013 at 11:21


I have looked into this gfortran-4.3 on Ubuntu 13.04, and I don’t see that anyone has yet made a PPA. I think at present you might have to compile gcc-4.4 and gfortran-4.3 from source. That would take some time I think.

Maybe a simpler workaround would be to compile your fortran code outside of matlab, setting your fortran code to read/write files for input/output. You can then consider using /dev/shm (RAM drive) as a speedy method of I/O (>1GB/sec). You use the /dev/shm RAM drive to pass data between matlab and your gfortran code–call the gfortran code from within Matlab using the SYSTEM() function.

I would consider doing this first as if it’s fast enough, you might save a day’s time of figuring out how to compile GCC/Gfortran from source. I have used this method with success when someone sends me binary (pre-compiled) program and the source code is unavailable. Or if someone sends me a Python program.

3 Trackbacks

[...] To use MEX for Matlab R2013a on Ubuntu 13.04, you must first have setup GCC 4.4 as described in: [...]

[...] By mhirsch | Posted in Linux, MATLAB / Octave | Tagged Ubuntu 13.10 [...]

[…] under a system where I can’t easily compile MEX-files (Ubuntu 13.04, Matlab2012b; Update: this issue can be solved), I wasn’t able to check it out myself. Anyway, the paper’s code is shorter than 200 […]

Post a Comment

Your email address is never shared. Required fields are marked *