| MATLAB® Compiler™ | ![]() |
Compile and link source files into standalone application or shared library
mbuild [option1 ... optionN] sourcefile1 [... sourcefileN] [objectfile1 ... objectfileN] [libraryfile1 ... libraryfileN] [exportfile1 ... exportfileN]
Note Supported types of source files are .c, .cpp, .idl, .rc. To specify IDL source files to be compiled with the Microsoft Interface Definition Language (MIDL) Compiler, add <filename>.idl to the mbuild command line. To specify a DEF file, add <filename>.def to the command line. To specify an RC file, add <filename>.rc to the command line. Source files that are not one of the supported types are passed to the linker. |
mbuild is a script that supports various options that allow you to customize the building and linking of your code. This table lists the set of mbuild options. If no platform is listed, the option is available on both UNIX® and Windows®.
| Option | Description |
|---|---|
| @<rspfile> | (Windows only) Include the contents of the text file <rspfile> as command line arguments to mbuild. |
| -<arch> | Build an output file for architecture -<arch>. To determine the value for -<arch>, type computer('arch') at the MATLAB® Command Prompt on the target machine. Note: Valid values for -<arch> depend on the architecture of the build platform. |
| -c | Compile only. Creates an object file only. |
| -D<name> | Define a symbol name to the C preprocessor. Equivalent to a #define <name> directive in the source. |
| -D<name>=<value> | Define a symbol name and value to the C preprocessor. Equivalent to a #define <name> <value> directive in the source. |
| -f <optionsfile> | Specify location and name of options file to use. Overrides the mbuild default options file search mechanism. |
| -g | Create an executable containing additional symbolic information for use in debugging. This option disables the mbuild default behavior of optimizing built object code (see the -O option). |
| -h[elp] | Print help for mbuild. |
| -I<pathname> | Add <pathname> to the list of directories to search for #include files. |
| -inline | Inline matrix accessor functions (mx*). The executable generated may not be compatible with future versions of MATLAB. |
| -l<name> | Link with object library. On Windows, <name> will be expanded to <name>.lib or lib<name>.lib and on UNIX to lib<name>. |
| -L<directory> | Add <directory> to the list of directories to search for libraries specified with the -l option. |
| -lang <language> | Specify compiler language. <language> can be c or cpp. By default, mbuild determines which compiler (C or C++) to use by inspection of the source file's extension. This option overrides that default. |
| -n | No execute mode. Print out any commands that mbuild would otherwise have executed, but do not actually execute any of them. |
| -O | Optimize the object code. Optimization is enabled by default and by including this option on the command line. If the -g option appears without the -O option, optimization is disabled. |
| -outdir <dirname> | Place all output files in directory <dirname>. |
| -output <resultname> | Create an executable named <resultname>. An appropriate executable extension is automatically appended. Overrides the mbuild default executable naming mechanism. |
| -regsvr | (Windows only) Use the regsvr32 program to register the resulting shared library at the end of compilation. MATLAB® Compiler™ uses this option whenever it produces a COM or .NET wrapper file. |
| -setup | Interactively specify the compiler options file to use as the default for future invocations of mbuild by placing it in the user profile directory (returned by the prefdir command). When this option is specified, no other command line input is accepted. |
| -U<name> | Remove any initial definition of the C preprocessor symbol <name>. (Inverse of the -D option.) |
| -v | Verbose mode. Print the values for important internal variables after the options file is processed and all command line arguments are considered. Prints each compile step and final link step fully evaluated. |
| <name>=<value> | Supplement or override an options file variable for variable <name>. This option is processed after the options file is processed and all command line arguments are considered. You may need to use the shell's quoting syntax to protect characters such as spaces that have a meaning in the shell syntax. On Windows double quotes are used (e.g., COMPFLAGS="opt1 opt2"), and on UNIX single quotes are used (e.g., CFLAGS='opt1 opt2'). It is common to use this option to supplement a variable already defined. To do this, refer to the variable by prepending a $ (e.g., COMPFLAGS="$COMPFLAGS opt2" on Windows or CFLAGS='$CFLAGS opt2' on UNIX). |
Note Some of these options (-f, -g, and -v) are available on the mcc command line and are passed along to mbuild. Others can be passed along using the -M option to mcc. For details on the -M option, see the mcc reference page. |
Note MBUILD can also create shared libraries from C source code. If a file with the extension .exports is passed to MBUILD, a shared library is built. The .exports file must be a text file, with each line containing either an exported symbol name, or starting with a # or * in the first column (in which case it is treated as a comment line). If multiple .exports files are specified, all symbol names in all specified .exports files are exported. |
To set up or change the default C/C++ compiler for use with the MATLAB Compiler product, use
mbuild -setup
To create a shared library named libfoo, use
mcc -W lib:libfoo -T link:lib foo.m
To compile and link an external C program foo.c against libfoo, use
mbuild foo.c -L. -lfoo (on UNIX) mbuild foo.c libfoo.lib (on Windows)
This assumes both foo.c and the library generated above are in the current working directory.
![]() | isdeployed | mcc | ![]() |
| © 1984-2008- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |