MATLAB Compiler | ![]() ![]() |
The MATLAB Compiler option flags perform various functions that affect the generated code and how the Compiler behaves. This table shows the categories of the Compiler options.
Category |
Purpose |
Macros |
The macro options simplify the compilation process by combining the most common compilation tasks into single options. |
Code Generation |
These options affect the actual code that the Compiler generates. For example, -L specifies the target language as either C or C++. |
Compiler and Environment |
These options provide information to the Compiler such as where to put (-d ) and find (-I ) particular files. |
mbuild/mex |
These options provide information for the mbuild and/or mex scripts. |
The remainder of this reference page is subdivided into sections that correspond to the Compiler option categories. Each section provides a full description of all of the options in the category.
The macro options provide a simplified way to accomplish basic compilation tasks.
-m (Stand-Alone C). Produce a stand-alone C application. It includes helper functions by default (-h
), and then generates a stand-alone C wrapper (-W main
). In the final stage, this option compiles your code into a stand-alone executable and links it to the MATLAB C/C++ Math Library (-T link:exe
). For example, to translate an M-file named mymfile.m
into C and to create a stand-alone executable that can be run without MATLAB, use
mcc -m mymfile
The -m
option is equivalent to the series of options
-W main -L C -t -T link:exe -h libmmfile.mlib
-p (Stand-Alone C++). Produce a stand-alone C++ application. It includes helper functions by default (-h
), and then generates a stand-alone C++ wrapper (-W main
). In the final stage, this option compiles your code into a stand-alone executable and links it to the MATLAB C/C++ Math Library (-T link:exe
). For example, to translate an M-file named mymfile.m
into C++ and to create a stand-alone executable that can be run without MATLAB, use
mcc -p mymfile
The -p
option is equivalent to the series of options
-W main -L Cpp -t -T link:exe -h libmmfile.mlib
-S (Simulink S-Function). Produce a Simulink S-function that is compatible with the Simulink S-function block. For example, to translate an M-file named mymfile.m
into C and to create the corresponding Simulink S-function using dynamically sized inputs and outputs, use
mcc -S mymfile
The -S
option is equivalent to the series of options
-W simulink -L C -t -T link:mex libmatlbmx.mlib
-x (MEX-Function). Produce a MEX-function. For example, to translate an M-file named mymfile.m
into C and to create the corresponding MEX-file that can be called directly from MATLAB, use
mcc -x mymfile
The -x
option is equivalent to the series of options
-W mex -L C -t -T link:mexlibrary libmatlbmx.mlib
-B sgl (Stand-Alone C Graphics Library). Produce a stand-alone C application that uses Handle Graphics.
The -B sgl
option is equivalent to the series of options
-m -W mainhg libmwsglm.mlib
-B sglcpp (Stand-Alone C++ Graphics Library). Produce a stand-alone C++ application that uses Handle Graphics.
The -B sglcpp
option is equivalent to the series of options
-p -W mainhg libmwsglm.mlib
-B pcode (MATLAB P-Code). Produce MATLAB P-code.
The -B pcode
option is equivalent to the series of options
-t -L P
-A (Annotation Control for Output Source). Control the type of annotation in the resulting C/C++ source file. The types of annotation you can control are:
annotation
)#line
preprocessor directive inclusion (line
)debugline
)To control the M-file code that is included in the generated C/C++ source, use
mcc -A annotation:type ...
This table shows the available types of code and comment annotation options.
To control the #line
preprocessor directives that are included in the generated C/C++ source, use
mcc -A line:setting ...
The table shows the available #line
directive settings.
To control if run-time error messages report the source file and line number, use
mcc -A debugline:on ...
This table shows the available debugline directive settings.
To include all of your M-code, including comments, in the generated file and the standard #line preprocessor directives, use
mcc -A annotation:all -A line:on ... or mcc -A line:on ... (The default is all for code/comment inclusion.)
To include none of your M-code and no #line
preprocessor directives, use
mcc -A annotation:none -A line:off ...
To include the standard #line
preprocessor directives in your generated C/C++ source code as well as source file and line number information in your run-time error messages, use
mcc -A line:on -A debugline:on ...
-F <option> (Formatting). Control the formatting of the generated code. This table shows the available options.
-g (Debug). This option is a macro that is equivalent to
-G -A debugline:on -O none
In addition to the -G
option, the -g
option includes the -A debugline:on
option. This will have an impact on performance of the generated code. If you wish to have debugging information, but do not want the performance degradation associated with the debug line information, use -g -A debugline:off
. The -g
option also includes the -O none
option, causing all compiler optimizations to be turned off. If you wish to have some optimizations on, you may specify them after the debug option.
-l (Line Numbers) . Generate C/C++ code that prints filename and line numbers on run-time errors. This option flag is useful for debugging, but causes the executable to run slightly slower. This option is equivalent to
mcc -A debugline:on ...
-L <language> (Target Language). Specify the target language of the compilation. Possible values for language are C
or Cpp
. The default is C
. Note that these values are case insensitive.
-O <option> (Optimization Options). Optimizes your M-file source code so that the performance of the generated C/C++ code may be faster than the performance of the M-code in the MATLAB interpreter. This table shows the available options.
-u (Number of Inputs). Provide more control over the number of valid inputs for your Simulink S-function. This option specifically sets the number of inputs (u
) for your function. If -u
is omitted, the input will be dynamically sized. (Used with -S
option.)
-W <type> (Function Wrapper). Control the generation of function wrappers for a collection of Compiler-generated M-files. You provide a list of functions and the Compiler generates the wrapper functions and any appropriate global variable definitions. This table shows the valid type options.
-y (Number of Outputs). Provides more control over the number of valid outputs for your Simulink S-function. This option specifically sets the number of outputs (y
) for your function. If -y
is omitted, the output will be dynamically sized. (Used with -S
option.)
Compiler and Environment Options
-B <filename> (Bundle of Compiler Settings). Replace -B <filename>
on the mcc
command line with the contents of the specified file. The file should contain only mcc
command line options and corresponding arguments and/or other filenames. The file may contain other -B
options.You can place options that you always set in an mccstartup
file. For more information, see "Setting Up Default Options.
-c (C Code Only). Generate C code but do not invoke mex
or mbuild
, i.e., do not produce a MEX-file or stand-alone application. This is equivalent to -T codegen
placed at the end of the mcc
command line.
-d <directory> (Output Directory). Place the output files from the compilation in the directory specified by the -d
option.
-h (Helper Functions). Compile helper functions. Any helper functions that are called will be compiled into the resulting MEX or stand-alone application. The -m
option automatically compiles all helper functions, so -m
effectively calls -h
.
Using the -h
option is equivalent to listing the M-files explicitly on the mcc
command line.
The -h
option purposely does not include built-in functions or functions that appear in the MATLAB M-File Math Library portion of the C/C++ Math Libraries. This prevents compiling functions that are already part of the C/C++ Math Libraries. If you want to compile these functions as helper functions, you should specify them explicitly on the command line. For example, use
mcc -m minimize_it fminsearch
mcc -m -h minimize_it
-I <directory> (Directory Path). Add a new directory path to the list of included directories. Each -I
option adds a directory to the end of the current search path. For example,
-I <directory1> -I <directory2>
would set up the search path so that directory1
is searched first for M-files, followed by directory2
. This option is important for stand-alone compilation where the MATLAB path is not available.
-o <outputfile>. Specify the basename of the final executable output (MEX-file or application) of the Compiler. A suitable, possibly platform-dependent, extension is added to the specified basename (e.g., .exe
for PC stand-alone applications, .mexsol
for Solaris MEX-files).
-t (Translate M to C/C++). Translate M-files specified on the command line to C/C++ files.
-T <target> (Output Stage). Specify the desired output stage. This table gives the possible values of target
.
-v (Verbose). Display the steps in compilation, including:
mex
or mbuild
The -v
option passes the -v
option to mex
or mbuild
and displays information about mex
or mbuild
.
-w (Warning). Display warning messages. This table shows the various ways you can use the -w option.
Syntax |
Description |
(no -w option) |
Default; displays only serious warnings. |
|
Generates a table that maps <string> to warning message for use with enable , disable , and error . The Error and Warning Messages appendix lists the same information. |
|
Enables complete warnings. |
|
Disables specific warning associated with <string>. The Error and Warning Messages appendix lists the valid <string> values. Leave off the optional :<string> to apply the disable action to all warnings. |
|
Enables specific warning associated with <string>. The Error and Warning Messages appendix lists the valid <string> values. Leave off the optional :<string> to apply the enable action to all warnings. |
|
Treats specific warning associated with <string> as error. Leave off the optional :<string> to apply the error action to all warnings. |
-Y <license.dat File>. Use license information in license.dat
file when checking out a Compiler license.
-f <filename> (Specifying Options File). Use the specified options file when calling mex
or mbuild
. This option allows you to use different compilers for different invocations of the MATLAB Compiler. This option is a direct pass-through to the mex
or mbuild
script. See External Interfaces/API for more information about using this option with the mex
script.
Note
Although this option works as documented, it is suggested that you use mex -setup or mbuild -setup to switch compilers.
|
-g (Debug Only). Cause mex
or mbuild
to invoke the C/C++ compiler with the appropriate C/C++ compiler options for debugging. You should specify -g
if you want to debug the MEX-file or stand-alone application with a debugger.
-M "string" (Direct Pass Through). Pass string
directly to the mex
or mbuild
script. This provides a useful mechanism for defining compile-time options, e.g., -M "-Dmacro=value"
.
-z <path> (Specifying Library Paths). Specify the path to use for library and include files. This option uses the specified path for compiler libraries instead of the path returned by matlabroot
.
Examples
Make a C translation and a MEX-file for myfun.m
.
mcc -x myfun
Make a C translation and a stand-alone executable for myfun.m
.
mcc -m myfun
Make a C++ translation and a stand-alone executable for myfun.m
.
mcc -p myfun
Make a C translation and a Simulink S-function for myfun.m
(using dynamically sized inputs and outputs).
mcc -S myfun
Make a C translation and a Simulink S-function for myfun.m
(explicitly calling for one input and two outputs).
mcc -S -u 1 -y 2 myfun
Make a C translation and stand-alone executable for myfun.m
. Look for myfun.m
in the /files/source
directory, and put the resulting C files and executable in the /files/target
directory.
mcc -m -I /files/source -d /files/target myfun
Make a C translation and a MEX-file for myfun.m
. Also translate and include all M-functions called directly or indirectly by myfun.m
. Incorporate the full text of the original M-files into their corresponding C files as C comments.
mcc -x -h -A annotation:all myfun
Make a generic C translation of myfun.m
.
mcc -t -L C myfun
Make a generic C++ translation of myfun.m
.
mcc -t -L Cpp myfun
Make a C MEX wrapper file from myfun1.m
and myfun2.m
.
mcc -W mex -L C myfun1 myfun2
Make a C translation and a stand-alone executable from myfun1.m
and myfun2.m
(using one mcc
call).
mcc -m myfun1 myfun2
Make a C translation and a stand-alone executable from myfun1.m
and myfun2.m
(by generating each output file with a separate mcc
call).
mcc -t -L C myfun1 % Yields myfun1.c mcc -t -L C myfun2 % Yields myfun2.c mcc -W main -L C myfun1 myfun2 % Yields myfun1_main.c mcc -T compile:exe myfun1.c % Yields myfun1.o mcc -T compile:exe myfun2.c % Yields myfun2.o mcc -T compile:exe myfun1_main.c % Yields myfun1_main.o mcc -T link:exe myfun1.o myfun2.o myfun1_main.o
![]() | mcc | MATLAB Compiler Quick Reference | ![]() |