Main Content

Change Default Compiler

To Change Default on Windows Systems

MATLAB® maintains separate default compiler options for C, C++, and Fortran language files. If you have multiple compilers that MATLAB supports for a language installed on your Windows® system, then MATLAB selects one as the default compiler. To change the default, use the mex -setup lang command. MATLAB displays a message with links to select a different default compiler.

If you call mex -setup without the lang argument, then MATLAB displays information about the default C compiler. MATLAB also displays links to the other supported languages. To change the default for another language, select a link.

If you call mex -setup from an operating system prompt, MATLAB displays the same information. However, the messages do not contain links. Instead, MATLAB displays the appropriate mex command syntax for changing the default compiler. Copy the command and paste it into the operating system prompt.

The compiler you choose remains the default for that language until you call mex -setup to select a different default.

C Compilers

To change the default C compiler, at the MATLAB command prompt, type:

mex -setup

mex -setup defaults to information about the C compiler. MATLAB also displays links to other C compilers on your system. To change the default, select one of these links.

Alternatively, type:

mex -setup c

C++ Compilers

To change the default C++ compiler, type:

mex -setup cpp

MATLAB displays information about the default C++ compiler and provides links to other C++ compilers on your system. To change the default, select one of these links. For an example, see Choose a C++ Compiler.

Fortran Compilers

To change the default Fortran compiler, type:

mex -setup Fortran

To Change Default on Linux Systems

For information about changing the gcc/g++ compiler to a supported version on Linux® platforms, see Change Default gcc Compiler on Linux System.

To Change Default on macOS Systems

If you have multiple versions of Xcode installed on your system, MATLAB uses the compiler defined by the Xcode.app application. You can use the compiler from an Xcode.X.app, where Xcode.X.app is the name you used to save a previously installed Xcode version.

Before starting MATLAB, from the Terminal type:

xcode-select -switch /Applications/Xcode.X.app/Contents/Developer

To see which Xcode MATLAB is using, at the Terminal type:

xcode-select -p

Do Not Use mex -f optionsfile Syntax

The mex command -f option to specify a build configuration file will be removed in a future release. Instead, use the workflows described in this topic for specifying a compiler.

See Also

Related Topics

External Websites