MATLAB Application Program Interface Reference Help Desk

The mex Script

Purpose

Compiles a MEX-function from C or FORTRAN source code

Syntax

Arguments

All non-source code file names passed as arguments are passed to the linker without being compiled.

These options are available on all platforms:

Option

Description

-argcheck

Add code to check validity of input arguments to MATLAB API functions (C functions only).

-c

Compile only; do not link.

-D<name>[=<def>]

Define preprocessor macro name <name> [as having value <def> (assignment not available under Windows)].

-f <file>

Use <file> as the options file; <file> is a full path name if not in current directory.

-g

Build a MEX-function with debugging symbols included.

-h[elp]

Help; print this message.

-I<pathname>

Include <pathname> in the compiler include path.

-O

Build an optimized MEX-function.

-output <name>

Create MEX-function named <name> (an appropriate MEX-file extension is automatically appended).

-V4

Compile MATLAB 4 compatible MEX-file.

-v

Verbose; print all compiler and linker settings.

These options are available on UNIX:

Option

Description

-l<file>

Link against library lib<file>.

-L<pathname>

Include <pathname> in the list of directories to search for libraries.

-U<name>

Undefine preprocessor macro name <name>.

<name>=<def>

Override options file setting for variable <name>.

This option is available on Windows:

Option

Description

-U<name>

Undefine preprocessor macro name <name>.

This option is available on Macintosh:

Option

Description

<name>=<def>

Override options file setting for variable <name>.

Description

MEX <options> <files> compiles a MEX-function from C or FORTRAN source code. All non-source code file names passed as arguments are passed to the linker without being compiled.

MEX's execution is affected by both command-line arguments and an options file. The options file contains all compiler-specific information necessary to create a MEX-function. The default name for this options file, if none is specified with the -f option, is mexopts.bat (Windows), mexopts.sh (UNIX), and mexopts (Macintosh).

On UNIX, the options file is written in the Bourne shell script language. The options file that occurs first in the following list is used:

Any variable specified in the options file can be overridden at the command line by use of the <name>=<def> command line argument. If <def> has spaces in it, then it should be wrapped in single quotes (e.g., OPTFLAGS='opt1 opt2'). The definition can rely on other variables defined in the options file; in this case the variable referenced should have a prepended $ (e.g., OPTFLAGS='$OPTFLAGS opt2').

On Windows, the options file is written in the Perl script language. The options file, mexopts.bat, is searched for in the following directories: the current directory first, then the same directory as mex.bat. No arguments can have an embedded equal sign (=); thus, -DFOO is valid, but -DFOO=BAR is not.

On the Macintosh, the options file is written in the MPW scripting language for MPW C and Language Systems Fortran, and in M-code language for Metrowerks Codewarrior C. The default location for the options file is the <MATLABROOT>:extern:scripts folder. Any variable specified in the options file can be overridden at the command line by use of the <name>=<def> command line argument. If <def> has spaces in it, then it should be wrapped in single quotes (e.g., OPTIMFLAGS='opt1 opt2'). The definition can rely on other variables defined in the options file; in this case the variable referenced should have a prepended $ (e.g., OPTIMFLAGS='$OPTIMFLAGS opt2').



[ Previous | Help Desk | Next ]