Learning Hub‎ > ‎

compile

MATLAB Compiler   
mcc 

Invoke MATLAB Compiler

Syntax

  • mcc [-options] mfile1       [mfile2 ... mfileN]
                                [C/C++file1 ... C/C++fileN]
    

Description

mcc is the MATLAB command that invokes the MATLAB Compiler. You can issue the mcc command either from the MATLAB command prompt (MATLAB mode) or the DOS or UNIX command line (stand-alone mode).

Command Line Syntax

You may specify one or more MATLAB Compiler option flags to mcc. Most option flags have a one-letter name. You can list options separately on the command line, for example:

  • mcc -m -g myfun
    

You can group options that do not take arguments by preceding the list of option flags with a single dash (-), for example:

  • mcc -mg myfun
    

Options that take arguments cannot be combined unless you place the option with its arguments last in the list. For example, these formats are valid:

  • mcc -m -A full myfun         % Options listed separately
    mcc -mA full myfun           % Options combined, A option last
    

This format is not valid:

  • mcc -Am full myfun           % Options combined, A option not last
    

In cases where you have more than one option that takes arguments, you can only include one of those options in a combined list and that option must be last. You can place multiple combined lists on the mcc command line.

If you include any C or C++ filenames on the mcc command line, the files are passed directly to mex or mbuild, along with any Compiler-generated C or C++ files.

Using Macros to Simplify Compilation

The MATLAB Compiler, through its exhaustive set of options, gives you access to the tools you need to do your job. If you want a simplified approach to compilation, you can use one simple option, i.e., macro, that allows you to quickly accomplish basic compilation tasks. If you want to take advantage of the power of the Compiler, you can do whatever you desire to do by choosing various Compiler options.

Table 7-2, Macro Options, shows the relationship between the macro approach to accomplish a standard compilation and the multioption alternative.

Table 7-2: Macro Options
Macro
Option

Bundle File
Creates
Option Equivalence

Translate M to C/C++
 | Function Wrapper
 |  |         Target Language
 |  |           |     Output Stage
 |  |           |      |          Helper Functions
 |  |           |      |           |
 |  |           |      |           |  M-File Library
 |  |           |      |           |     |

-m
macro_option_m
Stand-alone C application
-t -W main     -L C   -T link:exe -h     libmmfile.mlib
-p
macro_option_p
Stand-alone C++ application
-t -W main     -L Cpp -T link:exe -h     libmmfile.mlib
-x
macro_option_x
MEX-function
-t -W mex      -L C   -T link:mexlibrary libmatlbmx.mlib
-S
macro_option_S
Simulink S-function
-t -W simulink -L C   -T link:mex        libmatlbmx.mlib
-g
macro_option_g
Enable debug
-G -A debugline:on -O none

Understanding a Macro Option.   The -m option tells the Compiler to produce a stand-alone C application. The -m macro is equivalent to the series of options

  • -t -W main -L C -T link:exe -h libmmfile.mlib
    

Table 7-3, -m Macro, shows the options that compose the -m macro and the information that they provide to the Compiler.

Table 7-3: -m Macro 
Option
Function
-t
Translate M code to C/C++ code.
-W main
Produce a wrapper file suitable for a stand-alone application.
-L C
Generate C code as the target language.
-T link:exe
Create an executable as the output.
-h
Automatically, find and compile helper functions included in the source M-file.
libmmfile.mlib
Link to this shared library whenever necessary.

Changing Macro Options.   You can change the meaning of a macro option by editing the corresponding macro_option file bundle file in <matlab>/toolbox/compiler/bundles. For example, to change the -x macro, edit the file macro_option_x in the bundles directory.

Setting Up Default Options

If you have some command line options that you wish always to pass to mcc, you can do so by setting up an mccstartup file. Create a text file containing the desired command line options and name the file mccstartup. Place this file in one of two directories:

  • The current working directory, or
  • Your preferences directory ($HOME/.matlab/R13 on UNIX, <system root>\profiles\<user>\application data\mathworks\matlab\R13 on PC)

mcc searches for the mccstartup file in these two directories in the order shown above. If it finds an mccstartup file, it reads it and processes the options within the file as if they had appeared on the mcc command line before any actual command line options. Both the mccstartup file and the -B option are processed the same way.

    Note    If you need to change the meaning of a macro to satisfy your individual requirements, you should create or modify your mccstartup file in the preferences directory. Changing the file macro_option_x in the bundles directory changes the option for all Compiler users. To see the name of your preferences directory, type prefdir at the command prompt.

Setting a MATLAB Path in the Stand-Alone MATLAB Compiler

Unlike the MATLAB version of the Compiler, which inherits a MATLAB path from MATLAB, the stand-alone version has no initial path. If you want to set up a default path, you can do so by making an mccpath file. To do this:

  1. Create a text file containing the text -I <your_directory_here> for each directory you want on the default path, and name this file mccpath. (Alternately, you can call the mccsavepathM-function from MATLAB to create an mccpath file.)
  2. Place this file in your preferences directory. To do so, run the following commands at the MATLAB prompt:
    • cd(prefdir); mccsavepath;
      
  1. These commands save your current MATLAB path to a file named mccpath in your user preferences directory. (Type prefdir to see the name of your preferences directory.)

The stand-alone version of the MATLAB Compiler searches for the mccpath file in your current directory and then your preferences directory. If it finds an mccpath file, it processes the directories specified within the file and uses them to initialize its search path. Note that you may still use the -I option on the command line or in mccstartup files to add other directories to the search path. Directories specified this way are searched after those directories specified in the mccpath file.

Conflicting Options on Command Line

If you use conflicting options, the Compiler resolves them from left to right, with the rightmost option taking precedence. For example, using the equivalencies in Table 7-2, Macro Options,

  • mcc -m -W none test.m
    

is equivalent to

  • mcc -t -W main -L C -T link:exe -h -W none test.m
    

In this example, there are two conflicting -W options. After working from left to right, the Compiler determines that the rightmost option takes precedence, namely, -W none, and the Compiler does not generate a wrapper.

    Note    Macros and regular options may both affect the same settings and may therefore override each other depending on their order in the command line.

Handling Full Pathnames

If you specify a full pathname to an M-file on the mcc command line, the Compiler:

  1. Breaks the full name into the corresponding path- and filenames (<path> and <file>).
  2. Replaces the full pathname in the argument list with "-I <path> <file>". For example,
    • mcc -m /home/user/myfile.m
      
  1. would be treated as
    • mcc -m -I /home/user myfile.m
      

In rare situations, this behavior can lead to a potential source of confusion. For example, suppose you have two different M-files that are both named myfile.m and they reside in/home/user/dir1 and /home/user/dir2. The command

  • mcc -m -I /home/user/dir1 /home/user/dir2/myfile.m
    
  1. would be equivalent to
    • mcc -m -I /home/user/dir1 -I /home/user/dir2 myfile.m
      

The Compiler finds the myfile.m in dir1 and compiles it instead of the one in dir2 because of the behavior of the -I option. If you are concerned that this might be happening, you can specify the -v option and then see which M-file the Compiler parses. The -v option prints the full pathname to the M-file.

    Note    The Compiler produces a warning (specified_file_mismatch) if a file with a full pathname is included on the command line and it finds it somewhere else.

Compiling Embedded M-Files

If the M-file you are compiling calls other M-files, you can list the called M-files on the command line. Doing so causes the MATLAB Compiler to build all the M-files into a single MEX-file, which usually executes faster than separate MEX-files. Note, however, that the single MEX-file has only one entry point regardless of the number of input M-files. The entry point is the first M-file on the command line. For example, suppose that bell.m calls watson.m. Compiling with

  • mcc -x bell watson
    

creates bell.mex. The entry point of bell.mex is the compiled code from bell.m. The compiled version of bell.m can call the compiled version of watson.m. However, compiling as

  • mcc -x watson bell
    

creates watson.mex. The entry point of watson.mex is the compiled code from watson.m. The code from bell.m never gets executed.

As another example, suppose that x.m calls y.m and that y.m calls z.m. In this case, make sure that x.m is the first M-file on the command line. After x.m, it does not matter which order you specify y.m and z.m.

MATLAB Compiler Option Flags

The MATLAB Compiler option flags perform various functions that affect the generated code and how the Compiler behaves. Table 7-4, Compiler Option Categories, shows the categories of options.

Table 7-4: Compiler Option Categories  
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.

Macro Options

The macro options provide a simplified way to accomplish basic compilation tasks.

-g (Debug).   This option is a macro that is equivalent to

  • -G -A debugline:on -O none
    

or

  • -B macro_option_g
    

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 want 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 want to have some optimizations on, you may specify them after the debug option.

-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
    

or

  • -B macro_option_m
    

-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
    

or

  • -B macro_option_p
    

-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
    

or

  • -B macro_option_s
    

-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
    

or

  • -B macro_option_x
    

Bundle Files

-B ccom (C COM Object).   Produce a C COM object. The -B ccom option is equivalent to the series of options

  • -t -W com:<component_name>,<class_name>,<version> -T link:lib  
    -h libmmfile.mlib -i
    

-B cexcel (C Excel COM Object).   Produce a C Excel COM object. The -B cexcel option is equivalent to the series of options

  • -B excel:<component_name>,<class_name>,<version> -T link:lib 
    -h libmmfile.mlib -b -i
    

-B csglcom (C Handle Graphics COM Object).   Produce a C COM object that uses Handle Graphics. The -B csglcom option is equivalent to the series of options

  • -B sgl -t -W comhg:<component_name>,<class_name>,<version> 
    -T link:lib -h libmmfile.mlib -i
    

-B csglexcel (C Handle Graphics Excel COM Object).   Produce a C Excel COM object that uses Handle Graphics. The -B csglexcel option is equivalent to the series of options

  • -B sgl -t -W excelhg:<component_name>,<class_name>,<version> 
    -T link:lib -h libmmfile.mlib -b -i
    

-B csglsharedlib (C Handle Graphics Shared Library).   Produce a C shared library that uses Handle Graphics. The -B csglsharedlib option is equivalent to the series of options

  • -t -W libhg:<shared_library_name> -T link:lib -h libmmfile.mlib 
    libmwsglm.mlib
    

-B cppcom (C++ COM Object).   Produce a C++ COM object. The -B cppcom option is equivalent to the series of options

  • -B ccom:<component_name>,<class_name>,<version> -L cpp
    

-B cppexcel (C++ Excel COM Object).   Produce a C++ Excel COM object. The -B cppexcel option is equivalent to the series of options

  • -B cexcel:<component_name>,<class_name>,<version> -L cpp
    

-B cppsglcom (C++ Handle Graphics COM Object).   Produce a C++ COM object that uses Handle Graphics. The -B cppsglcom option is equivalent to the series of options

  • -B csglcom:<component_name>,<class_name>,<version> -L cpp
    

-B cppsglexcel (C++ Handle Graphics Excel COM Object).   Produce a C++ Excel COM object that uses Handle Graphics. The -B cppsglexcel option is equivalent to the series of options

  • -B csglexcel:<component_name>,<class_name>,<version> -L cpp
    

-B cpplib (C++ Library).   Produce a C++ library. The -B cpplib option is equivalent to the series of options

  • -B csharedlib:<shared_library_name> -L cpp -T compile:lib
    

-B csharedlib (C Shared Library).   Produce a C shared library. The -B csharedlib option is equivalent to the series of options

  • -t -W lib:<shared_library_name> -T link:lib -h libmmfile.mlib
    

-B pcode (MATLAB P-Code).   Produce MATLAB P-code.

The -B pcode option is equivalent to the series of options

  • -t -L P
    

-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
    

Code Generation Options

-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

  • M-file code and/or comment inclusion (annotation)
  • #line preprocessor directive inclusion (line)
  • Whether error messages report the source file and line number (debugline)

To control the M-file code that is included in the generated C/C++ source, use

  • mcc -A annotation:type ...
    

Table 7-5, Code/Comment Annotation Options, shows the available annotation options.

Table 7-5: Code/Comment Annotation Options
Type
Description
all
Provides the complete source of the M-file interleaved with the generated C/C++ source. The default is all.
comments
Provides all of the comments from the M-file interleaved with the generated C/C++ source.
none
No comments or code from the M-file are added to code. 

To control the #line preprocessor directives that are included in the generated C/C++ source, use

  • mcc -A line:setting ...
    

Table 7-6, Line Annotation Options, shows the available #line directive settings.

Table 7-6: Line Annotation Options
Setting
Description
on
Adds #line preprocessor directives to the generated 
C/C++ source code to enable source M-file debugging. Note: The page width option is ignored when this is on.
off
Adds no #line preprocessor directives to the generated C/C++ source code. The default is off.

To control if run-time error messages report the source file and line number, use

  • mcc -A debugline:on ...
    

Table 7-7, Run-Time Error Annotation Options, shows the available debugline directive settings.

Table 7-7: Run-Time Error Annotation Options
Setting
Description
on
Specifies the presence of source file and line number information in run-time error messages.
off
Specifies no source file and line number information in run-time error messages. The default is off.

For example, 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. Table 7-8, Formatting Options, shows the available options.

Table 7-8: Formatting Options  
<Option>
Description
list
Generates a table of all the available formatting options.
expression-indent:n
Sets the number of spaces of indentation for all expressions to n, where n is an integer. The default indent is 4.
page-width:n
Sets maximum width of generated code to n, where n is an integer. The default width is 80.
statement-indent:n
Sets the number of spaces of indentation for all statements to n, where n is an integer. The default indent is 2.

-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).   Optimize 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. Table 7-9, Optimization Options, shows the available options.

Table 7-9: Optimization Options  
<Option>
Description
-O list
Lists all available optimizations.
-O all
Turns on all optimizations; all is the default. Equivalent to -B opt_bundle_all.
-O none
Turns off all optimizations. Equivalent to -B opt_bundle_none.
-O <opt option>:[on|off]

Enables or disables individual optimizations, where
<opt option> is:

  • array_indexing
  • fold_mxarrays
  • fold_non_scalar_mxarrays
  • fold_scalar_mxarrays
  • optimize_conditionals
  • optimize_integer_for_loops
  • percolate_simple_types
  • speculate

-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. (Use this with the -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. Table 7-10, Function Wrapper Types, shows the valid options.

Table 7-10: Function Wrapper Types  
<Type>
Description
mex
Produces a mexFunction() interface.
main
Produces a POSIX shell main() function.
simulink
Produces a Simulink C MEX S-function interface.
lib:<string>
Produces an initialization and termination function for use when compiling this Compiler-generated code into a larger application. This option also produces a header file containing prototypes for all public functions in all M-files specified. <string> becomes the base (file) name for the generated C/C++ and header file. Creates a.exports file that contains all nonstatic function names.
com:<component_name>[,<class_name>
 [,<major>.<minor>]]

Produces a COM object from MATLAB M-files.
comhg:<component_name>[,<class_name>
 [,<major>.<minor>]]

Produces a Handle Graphics COM object from MATLAB M-files.
excel:<component_name>[,<class_name>
 [,<major>.<minor>]]

Produces a COM object from MATLAB M-files.
excelhg:<component_name>[,<class_name>
 [,<major>.<minor>]]

Produces a Handle Graphics COM object from MATLAB M-files.
none
Does not produce a wrapper file. The default is none.
    Caution    When generating function wrappers, you must specify all M-files that are being linked together on the command line. These files are used to produce the initialization and termination functions as well as global variable definitions. If the functions are not specified in this manner, undefined symbols will be produced at link time or run-time crashes may occur.

-y (Number of Outputs).   Provide 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. (Use this with the -S option.)

Compiler and Environment Options

-b (Visual Basic File).   Generate a Visual Basic file (.bas) that contains the Microsoft Excel Formula Function interface to the Compiler-generated COM object.When imported into the workbook Visual Basic code, this code allows the MATLAB function to be seen as a cell formula function.

-B <filename>:[<a1>,<a2>,...,<an>] (Bundle of Compiler Settings).   Replace -B <filename>:[<a1>,<a2>,...,<an>] 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.

A bundle file can include replacement parameters for Compiler options that accept names and version numbers. For example, there is a bundle file for C shared libraries, csharedlib, that consists of

  • -t -W lib:%1% -T link:lib -h libmmfile.mlib
    

To invoke the Compiler to produce a C shared library using this bundle, you would use

  • mcc -B csharedlib:mysharedlib <f1>,<f2>,...
    

In general, each %n% in the bundle file will be replaced with the corresponding option specified to the bundle file. Use %% to include a % character. It is an error to have too many or too few options to the bundle file.

You can place options that you always set in an mccstartup file. For more information, see Setting Up Default Options.

    Note    You can use the -B option with a replacement expression as is at the DOS or UNIX prompt. To use -B with a replacement expression at the MATLAB prompt, you must enclose the expression that follows the -B in single quotation marks. For example:

        >>mcc -B 'csharedlib:libtimefun' weekday data tic calendar toc

This table shows the available bundle files.

Bundle File Name
Contents
ccom
-t -W com:<component_name>,<class_name>,<version> -T link:lib -h libmmfile.mlib -i
cexcel
-B excel:<component_name>,<class_name>,<version> -T link:lib -h libmmfile.mlib -b -i
csglcom
-B sgl -t -W comhg:<component_name>,<class_name>,<version> -T link:lib -h libmmfile.mlib
csglexcel
-B sgl -t -W excelhg:<component_name>,<class_name>,<version> -T link:lib -h libmmfile.mlib -b -i
csglsharedlib
-t -W libhg:<shared_library_name> -T link:lib -h libmmfile.mlib libmwsglm.mlib
cppcom
-B ccom:<component_name>,<class_name>,<version> -L cpp
cppexcel
-B cexcel:<component_name>,<class_name>,<version> -L cpp
cppsglcom
-B chgcom:<component_name>,<class_name>,<version> -L cpp
cppsglexcel
-B csglexcel:<component_name>,<class_name>,<version> -L cpp
cpplib
-B csharedlib:<shared_library_name> -L cpp -T compile:lib
csharedlib
-t -W lib:<shared_library_name> -T link:lib -h libmmfile.mlib
macro_default
-O all
macro_option_g
-G -A debugline:on -O none
macro_option_m
-W main -L C -t -T link:exe -h libmmfile.mlib
macro_option_p
-W main -L cpp -t -T link:exe -h libmmfile.mlib
macro_option_S
-W simulink -L C -t -T link:mex libmatlbmx.mlib
macro_option_x
-W mex -L C -t -T link:mexlibrary libmatlbmx.mlib
opt_bundle_all
-O fold_scalar_mxarrays:on
-O fold_non_scalar_mxarrays:on
-O optimize_integer_for_loops:on
-O array_indexing:on
-O optimize_conditionals:on
opt_bundle_none
-O fold_scalar_mxarrays:off 
-O fold_non_scalar_mxarrays:off 
-O optimize_integer_for_loops:off 
-O array_indexing:off
-O optimize_conditionals:off
-O speculate:off
pcode
-t -L P
sgl
-m -W mainhg libmwsglm.mlib
sglcpp
-p -W mainhg libmwsglm.mlib

-c (C Code Only).   When used with a macro option, 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
    

instead of

  • mcc -m -h minimize_it
    

-i (Include Exported Interfaces).   Cause the Compiler to include only the M-files that are specified on the command line as exported interfaces. If additional M-files are compiled as a result of being located by the -h option, they are not included in the exported interface that is produced by the MATLAB Compiler.

-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 (stand-alone applications only) of the Compiler. A suitable, possibly platform-dependent, extension is added to the specified basename (e.g., .exe for PC stand-alone applications).

    Note    You cannot use this option to specify a different name for a MEX-file.

-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. Table 7-11, Output Stage Options, gives the possible values of target.

Table 7-11: Output Stage Options  
<Target>
Description
codegen
Translates M-files to C/C++ files and generates a wrapper file. The default is codegen.
compile:mex
Same as codegen plus compiles C/C++ files to object form suitable for linking into a Simulink S-function MEX-file.
compile:mexlibrary
Same as codegen plus compiles C/C++ files to object form suitable for linking into an ordinary (non-S-function) MEX-file.
compile:exe
Same as codegen plus compiles C/C++ files to object form suitable for linking into a standalone executable.
compile:lib
Same as codegen plus compiles C/C++ files to object form suitable for linking into a shared library/DLL.
link:mex
Same as compile:mex plus links object files into a Simulink S-function MEX-file.
link:mexlibrary
Same as compile:mexlibrary plus links object files into an ordinary (non-S-function) MEX-file.
link:exe
Same as compile:exe plus links object files into a standalone executable.
link:lib
Same as compile:lib plus links object files into a shared library/DLL.
    mex and mexlibrary use the mex script to build a MEX-file; exe uses the mbuild script to build an executable; lib uses mbuild to build a shared library.

-v (Verbose).   Display the steps in compilation, including

  • The Compiler version number
  • The source filenames as they are processed
  • The names of the generated output files as they are created
  • The invocation of 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. Table 7-12, Warning Option, shows the various ways you can use the -w option.

Table 7-12: Warning Option  
Syntax
Description
(no -w option)
Default; displays only serious warnings.
-w list
Generates a table that maps <string> to warning message for use with enabledisable, and errorAppendix BError and Warning Messages lists the same information.
-w
Enables complete warnings.
-w disable[:<string>]
Disables specific warning associated with <string>Appendix BError and Warning Messages lists the valid <string> values. Leave off the optional :<string> to apply the disable action to all warnings.
-w enable[:<string>]
Enables specific warning associated with <string>Appendix BError and Warning Messages lists the valid <string> values. Leave off the optional :<string> to apply the enable action to all warnings.
-w error[:<string>]
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.

mbuild/mex Options

-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 in the MATLAB documentation for more information about using this option with the mex script.

    Note    Although this option works as documented, we suggest 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".

    Note    Multiple -M options do not accumulate; only the last -M option is used.

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

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
    
    Note    On PCs, filenames ending with .o above would actually end with .obj.

Compile plus1.m into an Excel add-in:

  • mcc -B 'cexcel:addin:addin:1.0' plus1.m
    


  mbuild MATLAB Compiler Quick Reference 

Comments