Matlab Fortran MEX setup

Test that Matlab MEX C / C++ compiler wrapper is working on your system with a supported compiler. These commands are all from within Matlab.

Setup Matlab for Fortran compiler:

mex -setup -v fortran

Verify configuration by


Copy over an example Fortran program.

copyfile(fullfile(matlabroot,'extern','examples','refbook','timestwo.F'), pwd)
copyfile(fullfile(matlabroot,'extern','include','fintrf.h'), pwd)


mex timestwo.F



ans = 6.0

If problems, check Matlab compiler setup.

Matlab and Fortran on Windows can use Intel oneAPI to compile Fortran.

GNU Octave and Gfortran MEX are available on Windows, MacOS and Linux.