Documentation

Changing 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

Mac and Linux Systems

MATLAB supports only one compiler for each language on Linux® and Mac 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.

Change System Default Compiler

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

!which gcc

If this is not a MATLAB-supported compiler, you can change the default. This becomes the default compiler for all applications on your system. To change the system default compiler:

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 yprime.c, type:

copyfile(fullfile(matlabroot,'extern','examples','refbook','timestwo.c'),'.','f')
mex -v GCC='/usr/bin/gcc-4.7' timestwo.c

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

External Web Sites

Was this topic helpful?