This is machine translation

Translated by Microsoft
Mouse over text to see original. Click the button below to return to the English verison of the page.

Change Default Compiler

Windows Systems

If you have multiple MATLAB®-supported compilers for a language installed on your Windows® system, MATLAB selects one as the default compiler. You can change the default using the mex -setup language command. If you have multiple compilers, MATLAB displays a message with links to set up a different compiler.

If you call mex -setup without the language argument, MATLAB displays links to the other supported languages. Select a link to change the default for building MEX files in that language. MATLAB maintains separate default compiler options for C language and C++ language files.

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 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

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 work flows described in this topic for specifying a compiler.

See Also

Related Examples

More About

External Websites

Was this topic helpful?