mcc

Compile MATLAB functions for deployment

Syntax

  • mcc options mfilename1,...,mfilenameN
  • mcc -W excel:addin_name,className,version -T link:lib options mfilename1,...,mfilenameN
    example
  • mcc -H -W hadoop:archiveName,CONFIG:configFile

Description

mcc options mfilename1,...,mfilenameN compiles the functions as specified by the options.

The options used depend on the intended results of the compilation. For information on compiling:

  • C/C++ shared libraries, .NET assemblies, Java® packages, or Python® packages see mcc for MATLAB® Compiler SDK™

  • MATLAB Production Server™ deployable archives or Excel® add-ins for MATLAB Production Server see mcc for MATLAB Compiler SDK

example

mcc -m options mfilename compiles the function into a standalone application.

This is equivalent to -W main -T link:exe.

example

mcc -e options mfilename compiles the function into a standalone application that does not open an MS-DOS® command window.

This syntax is equivalent to -W WinMain -T link:exe.

example

mcc -W excel:addin_name,className,version -T link:lib options mfilename1,...,mfilenameN creates a Microsoft® Excel add-in from the specified files.

  • addin_name — Specifies the name of the addin and its namespace, which is a period-separated list, such as companyname.groupname.component.

  • className — Specifies the name of the class to be created. If you do not specify the class name, mcc uses the addin_name as the default.

  • version — Specifies the version of the add-in specified as major.minor.

    • major — Specifies the major version number. If you do not specify a version number, mcc uses the latest version.

    • minor — Specifies the minor version number. If you do not specify a version number, mcc uses the latest version.

mcc -H -W hadoop:archiveName,CONFIG:configFile generates a deployable archive that can be run as a job by Hadoop®.

  • archiveName — Specifies the name of the generated archive.

  • configFile — Specifies the path to the Hadoop settings file. See Hadoop Settings File.

    Tip   You can issue the mcc command either at the MATLAB command prompt or the DOS or UNIX® command line.

Examples

Compile a standalone application

mcc -m magic.m

Compile a standalone Windows application

Compile a standalone application that does not open a command prompt on Windows.

mcc -e magic.m

Compile an Excel add-in

mcc -W excel:myMagin,magic, -T link:lib magic.m

Input Arguments

collapse all

mfilename — File to be compiledfilename

File to be compiled specified as a string.

mfilename1,...,mfilenameN — Files to be compiledlist of filenames

One, or more, files to be compiled, specified as a comma-separated list of filenames.

options — Options for customizing the output-a | -b | -B | -C | -d | -f | -g | -G | -I | -K | -m | -M | -N | -o | -p | -R | -S | -T | -u | -v | -w | -W | -Y

Options for customizing the output, specified as a list of strings.

  • -a

    Add files to the deployable archive using -a path to specify the files to be added. Multiple -a options are permitted.

    If a file name is specified with -a, the compiler looks for these files on the MATLAB path, so specifying the full path name is optional. These files are not passed to mbuild, so you can include files such as data files.

    If a folder name is specified with the -a option, the entire contents of that folder are added recursively to the deployable archive. For example

    mcc -m hello.m -a ./testdir 

    specifies that all files in testdir, as well as all files in its subfolders, are added to the deployable archive. The folder subtree in testdir is preserved in the deployable archive.

    If the filename includes a wildcard pattern, only the files in the folder that match the pattern are added to the deployable archive and subfolders of the given path are not processed recursively. For example

    mcc -m hello.m -a ./testdir/*

    specifies that all files in ./testdir are added to the deployable archive and subfolders under ./testdir are not processed recursively.

    mcc -m hello.m -a ./testdir/*.m

    specifies that all files with the extension .m under ./testdir are added to the deployable archive and subfolders of ./testdir are not processed recursively.

      Note:   * is the only supported wildcard.

    When you add files to the archive using -a that do not appear on the MATLAB path at the time of compilation, a path entry is added to the application's run-time path so that they appear on the path when the deployed code executes.

    When you include files, the absolute path for the DLL and header files changes. The files are placed in the .\exe_mcr\ folder when the archive is expanded. The file is not placed in the local folder. This folder is created from the deployable archive the first time the application is executed. The isdeployed function is provided to help you accommodate this difference in deployed mode.

    The -a switch also creates a .auth file for authorization purposes. It ensures that the executable looks for the DLL- and H-files in the exe_mcr\exe folder.

      Caution   If you use the -a flag to include a file that is not on the MATLAB path, the folder containing the file is added to the MATLAB dependency analysis path. As a result, other files from that folder might be included in the compiled application.

      Note:   If you use the -a flag to include custom Java classes, standalone applications work without any need to change the classpath as long as the Java class is not a member of a package. The same applies for JAR files. However, if the class being added is a member of a package, the MATLAB code needs to make an appropriate call to javaaddpath to update the classpath with the parent folder of the package.

  • -b

    Generate a Visual Basic® file (.bas) containing the Microsoft Excel Formula Function interface to the COM object generated by MATLAB Compiler™. When imported into the workbook Visual Basic code, this code allows the MATLAB function to be seen as a cell formula function.

  • -B

    Replace the file on the mcc command line with the contents of the specified file. Use

    -B filename[:<a1>,<a2>,...,<an>]
    

    The bundle filename should contain only mcc command-line options and corresponding arguments and/or other file names. The file might contain other -B options. A bundle can include replacement parameters for compiler options that accept names and version numbers. See Using Bundles to Build MATLAB Code.

  • -C

    Do not embed the deployable archive in binaries.

  • -d

    Place output in a specified folder. Use

    -d outFolder
    

    to direct the generated files to outFolder.

  • -f

    Override the default options file with the specified options file. Use

    -f filename
    

    to specify filename as the options file when calling mbuild. This option lets you use different ANSI compilers for different invocations of the compiler. This option is a direct pass-through to mbuild.

  • -g, -G

    Include debugging symbol information for the C/C++ code generated by MATLAB Compiler SDK. It also causes mbuild to pass appropriate debugging flags to the system C/C++ compiler. The debug option lets you backtrace up to the point where you can identify if the failure occurred in the initialization of MATLAB Runtime, the function call, or the termination routine. This option does not let you debug your MATLAB files with a C/C++ debugger.

  • -I

    Add a new folder path to the list of included folders. Each -I option adds a folder to the beginning of the list of paths to search. For example,

    -I <directory1> -I <directory2>
    

    sets up the search path so that directory1 is searched first for MATLAB files, followed by directory2. This option is important for standalone compilation where the MATLAB path is not available.

    If used in conjunction with the -N option, the -I option adds the folder to the compilation path in the same position where it appeared in the MATLAB path rather than at the head of the path.

  • -K

    Direct mcc not to delete output files if the compilation ends prematurely, due to error.

    The default behavior of mcc is to dispose of any partial output if the command fails to execute successfully.

  • -m

    Direct mcc to generate a standalone application.

  • -M

    Define compile-time options. Use

    -M string
    

    to pass string directly to mbuild. This provides a useful mechanism for defining compile-time options, e.g., -M "-Dmacro=value".

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

  • -N

    Passing -N clears the path of all folders except the following core folders (this list is subject to change over time):

    • matlabroot\toolbox\matlab

    • matlabroot\toolbox\local

    • matlabroot\toolbox\compiler

    Passing -N also retains all subfolders in this list that appear on the MATLAB path at compile time. Including -N on the command line lets you replace folders from the original path, while retaining the relative ordering of the included folders. All subfolders of the included folders that appear on the original path are also included. In addition, the -N option retains all folders that you included on the path that are not under matlabroot\toolbox.

    When using the –N option, use the –I option to force inclusion of a folder, which is placed at the head of the compilation path. Use the –p option to conditionally include folders and their subfolders; if they are present in the MATLAB path, they appear in the compilation path in the same order.

  • -o

    Specify the name of the final executable (standalone applications only). Use

    -o outputfile
    

    to name the final executable output of MATLAB Compiler. A suitable platform-dependent extension is added to the specified name (e.g., .exe for Windows® standalone applications).

  • -p

    Use in conjunction with the option -N to add specific folders and subfolders under matlabroot\toolbox to the compilation MATLAB path. The files are added in the same order in which they appear in the MATLAB path. Use the syntax

    -N -p directory
    

    where directory is the folder to be included. If directory is not an absolute path, it is assumed to be under the current working folder.

    • If a folder is included with -p that is on the original MATLAB path, the folder and all its subfolders that appear on the original path are added to the compilation path in the same order.

    • If a folder is included with -p that is not on the original MATLAB path, that folder is ignored. (You can use -I to force its inclusion.)

  • -R

    Provides MATLAB Runtime options. The syntax is as follows:

    -R option

    Option

    Description

    Target

    -logfile,filename

    Specify a log file name.

    MATLAB Compiler

    MATLAB Compiler SDK

    -nodisplay

    Suppress the MATLAB nodisplay run-time warning.

    MATLAB Compiler

    MATLAB Compiler SDK

    -nojvm

    Do not use the Java Virtual Machine (JVM).

    MATLAB Compiler

    MATLAB Compiler SDK

    -startmsg

    Customizable user message displayed at initialization time.

    MATLAB Compiler

    Standalone Applications

    -completemsg

    Customizable user message displayed when initialization is complete.

    MATLAB Compiler

    Standalone Applications

      Caution   When running on Mac OS X, if you use -nodisplay as one of the options included in mclInitializeApplication, then the call to mclInitializeApplication must occur before calling mclRunMain.

  • -S

    The standard behavior for the MATLAB Runtime is that every instance of a class gets its own MATLAB Runtime context. The context includes a global MATLAB workspace for variables, such as the path and a base workspace for each function in the class. If multiple instances of a class are created, each instance gets an independent context. This ensures that changes made to the global, or base, workspace in one instance of the class does not affect other instances of the same class.

    In a singleton MATLAB Runtime, all instances of a class share the context. If multiple instances of a class are created, they use the context created by the first instance. This saves startup time and some resources. However, any changes made to the global workspace or the base workspace by one instance impacts all class instances. For example, if instance1 creates a global variable A in a singleton MATLAB Runtime, then instance2 can use variable A.

    Singleton MATLAB Runtime is only supported by the following products on these specific targets:

    Target supported by Singleton MATLAB RuntimeCreate a Singleton MATLAB Runtime by....
    Excel add-inDefault behavior for target is singleton MATLAB Runtime. You do not need to perform other steps.
    .NET assemblyDefault behavior for target is singleton MATLAB Runtime. You do not need to perform other steps.
    COM component
    • Using the Library Compiler app, click Settings and add -S to the Additional parameters to pass to mcc field.

    • Using mcc, pass the -S flag.

    Java package

  • -T

    Specify the output target phase and type.

    Use the syntax -T target to define the output type.

    TargetDescription
    compile:exeGenerate a C/C++ wrapper file and compile C/C++ files to an object form suitable for linking into a standalone application.
    compile:libGenerate a C/C++ wrapper file and compile C/C++ files to an object form suitable for linking into a shared library or DLL.
    link:exeSame as compile:exe, and also links object files into a standalone application.
    link:libSame as compile:lib, and also links object files into a shared library or DLL.

  • -u

    Register COM component for the current user only on the development machine. The argument applies only to the generic COM component and Microsoft Excel add-in targets.

  • -v

    Display the compilation steps, including:

    • MATLAB Compiler version number

    • The source file names as they are processed

    • The names of the generated output files as they are created

    • The invocation of mbuild

    The -v option passes the -v option to mbuild and displays information about mbuild.

  • -w

    Display warning messages. Use the syntax

    -w option [:<msg>]

    to control the display of warnings.

    Syntax

    Description

    -w list

    List all of the possible warning that mcc can generate.

    -w enable

    Enable complete warnings.

    -w disable[:<string>]

    Disable specific warnings associated with <string>. See Warning Messages for a list of the <string> values. Omit the optional <string> to apply the disable action to all warnings.

    -w enable[:<string>]

    Enable specific warnings associated with <string>. See Warning Messages for a list of the <string> values. Omit the optional <string> to apply the enable action to all warnings.

    -w error[:<string>]

    Treat specific warnings associated with <string> as an error. Omit the optional <string> to apply the error action to all warnings.

    -w off[:<string>] [<filename>]

    Turn warnings off for specific error messages defined by <string>. You can also narrow scope by specifying warnings be turned off when generated by specific <filename>s.

    -w on[:<string>] [<filename>]

    Turn warnings on for specific error messages defined by <string>. You can also narrow scope by specifying warnings be turned on when generated by specific <filename>s.

    You can also turn warnings on or off in your MATLAB code.

    For example, to turn warnings off for deployed applications (specified using isdeployed) in your startup.m, you write:

    if isdeployed
        warning off
    end
    

    To turn warnings on for deployed applications, you write:

    if isdeployed
        warning on
    end
    
  • -W

    Control the generation of function wrappers. Use the syntax

    -W type 

    to control the generation of function wrappers for a collection of MATLAB files generated by the compiler. You provide a list of functions and the compiler generates the wrapper functions and any appropriate global variable definitions.

  • -Y Use

     -Y license.lic

    to override the default license file with the specified argument.

      Note:   The -Y flag works only with the command-line mode.

      >>!mcc -m foo.m -Y license.lic

Introduced before R2006a

Was this topic helpful?