Change Default Compiler

Windows Systems

MATLAB® maintains separate default compiler options for C, C++, and Fortran language files. If you have multiple MATLAB-supported compilers 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. Alternatively, type:

mex -setup c

C++ Compilers

To change the default C++ compiler, type:

mex -setup cpp

For an example, see Choose a C++ Compiler.

Fortran Compilers

To change the default Fortran compiler, type:

mex -setup Fortran

Change Linux System Default Compiler

MATLAB supports only one compiler for each language on Linux® platforms. If you have multiple compilers installed, the default compiler might not be the MATLAB-supported compiler. You can either change the system default compiler for all applications, or select the MATLAB-supported compiler each time you run the mex command.

To determine the default gcc compiler for your system, in MATLAB, type:

!which gcc

Change System $PATH Variable

You can change the default compiler by editing the system $PATH variable. When you change the path, this compiler becomes the default for all applications on your system.

To change the $PATH variable, add the folder containing the MATLAB-supported compiler to the beginning of the path. Refer to your operating system documentation for the correct command to use.

Select MATLAB-Supported Compiler When Running mex

To change the compiler in the mex command, set the varname variable. varname for the gcc compiler is GCC, in uppercase letters. For example, if the currently supported gcc compiler is version 4.7, and it is installed in the /usr/bin/gcc-4.7 folder on your system, to build timestwo.c, type:

mex -v GCC='/usr/bin/gcc-4.7' timestwo.c

Setting the compiler using the mex command does not change the system default compiler.

Use Non-Default Compiler on Mac Systems

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

Before starting MATLAB, from the Terminal type:

xcode-select -switch /Applications/

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