Matlab MinGW / Intel compiler setup

Matlab requires C / C++ / Fortran compilers for numerous operations such as mex, loadlibrary and more. Windows Matlab supported compilers include MinGW GNU compilers for Windows for C and C++, Visual Studio, or Intel oneAPI compilers for C / C++ / Fortran.

Matlab uses environment variables to communicate the location of specific compiler versions. Tell Matlab the MinGW compiler path via Windows environment variable “MW_MINGW_LOC”. On Windows, Matlab with Fortran needs Intel oneAPI compiler.

Find the MinGW compiler location from Terminal using where.exe gcc (Windows) or which gcc. Assuming MinGW is under “C:/msys64/mingw64/bin/gcc.exe”, in Matlab:

setenv('MW_MINGW64_LOC', 'C:/msys64/mingw64')

One-time setup MEX C / C++:

mex -setup -v

mex -setup -v C++

Intel oneAPI Fortran compiler with Matlab is setup by:

mex -setup Fortran -v
mex -setup -v

If problem finding compiler, find the Intel compiler location using where.exe ifx (Windows) or which ifx. Assuming Intel compiler location is at “C:/Program Files (x86)/Intel/oneAPI/compiler/latest/windows/bin/intel64/ifx.exe”

setenv('ICPP_COMPILER20', 'C:/Program Files (x86)/Intel/oneAPI/compiler/latest/windows')
setenv('IFORT_COMPILER20', 'C:/Program Files (x86)/Intel/oneAPI/compiler/latest/windows')

Verify Matlab MEX parameters are displayed in Matlab by: