mbuild

Compile and link source files against MATLAB generated shared libraries

Syntax

mbuild [option1 ... optionN] sourcefile1 [... sourcefileN]
   [objectfile1 ... objectfileN] [libraryfile1 ... libraryfileN]

Description

mbuild compiles and links customer written C or C++ code against MATLAB® generated shared libraries.

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.

Supported Source File Types

Supported types of source files are:

  • .c

  • .cpp

Source files that are not one of the supported types are pass ed to the linker.

Options

This table lists the set of mbuild options. If no platform is listed, the option is available on both UNIX® and Windows®.

OptionDescription
@<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 folders to search for #include files.

-l<name>

Link with object library. On Windows systems, <name> expands to <name>.lib or lib<name>.lib and on UNIX systems, to lib<name>.so or lib<name>.dylib. Do not add a space after this switch.

    Note:   When linking with a library, it is essential that you first specify the path (with -I<pathname>, for example).

-L<folder>

Add <folder> to the list of folders to search for libraries specified with the -l option. On UNIX systems, you must also set the run-time library paths. Do not add a space after this switch.

-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 folder <dirname>.

-output <resultname>

Create an executable named <resultname>. An appropriate executable extension is automatically appended. Overrides the mbuild default executable naming mechanism.

-setup

Interactively specify the C/C++ compiler options file to use as the default for future invocations of mbuild by placing it in the user profile folder (returned by the prefdir command). When this option is specified, no other command line input is accepted.

-setup -client mbuild_com

Interactively specify the COM compiler options file to use as the default for future invocations of mbuild by placing it in the user profile folder (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 shell).

Examples

To change the default C/C++ compiler for use with MATLAB Compiler SDK™, use

mbuild -setup

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

Was this topic helpful?