Choose a C++ Compiler

Select Microsoft Visual Studio Compiler

This example shows how to determine and change the default compiler for building C++ MEX files when you have multiple versions of Microsoft® Visual Studio® on your system. The messages in this example assume that you have Microsoft Visual C++® 2012 and Microsoft Visual C++ 2015. Use these steps for any C++ compilers on your system.

MATLAB® chooses a default compiler for C source files and a default compiler for C++ source files. To see the default C++ compiler, type:

mex -setup c++
MEX configured to use 'Microsoft Visual C++ 2012' for C++ language compilation.

MATLAB also displays links to other C++ compilers installed on your system.

To change the default to MSVC 2015, click the link:

Microsoft Visual C++ 2015 Professional (C)  
MEX configured to use 'Microsoft Visual C++ 2015 Professional (C)' for C++ language compilation.

Microsoft Visual C++ 2015 remains the default until you call mex -setup c++ to select a different default.

When you call the mex command with a source file, MATLAB displays the name of the compiler used to build the MEX file. You can also find this information using the mex -setup lang command. By default, when you type mex -setup, MATLAB shows you information for the C compiler only. If you want information for C++ compilers, type:

mex -setup c++

Select MinGW-w64 Compiler

If you only have the MinGW® compiler installed on your system, the mex command automatically chooses MinGW for both C and C++ MEX files. If you have multiple C or C++ compilers, use mex -setup to choose MinGW for both C and C++ MEX files.

mex -setup
mex -setup cpp

If you only type mex -setup choosing MinGW, when you compile a C++ file, mex might choose a different compiler.

Related Topics