External Interfaces/API Reference    
The mex Script

Compiles a MEX-function from C or Fortran source code

Syntax

Arguments

All nonsource code filenames passed as arguments are passed to the linker without being compiled.

These options are available on all platforms except where noted.

Option
Function
@<rsp_file>
Include the contents of the text file <rsp_file> as command line arguments to the mex script.
-argcheck
Perform argument checking on MATLAB API functions (C functions only).
-c
Compile only. Do not link.
-D<name>[#<def>]
Define C preprocessor macro <name> [as having value <def>]. (Note: UNIX also allows -D<name>[=<def>].)
-f <file>
Use <file> as the options file; <file> is a full pathname if it is not in current directory.
-g
Build an executable with debugging symbols included.
-h[elp]
Help. Lists the switches and their functions.
-I<pathname>
Include <pathname> in the compiler include search path.
-inline
Inlines matrix accessor functions (mx*). The generated MEX-function may not be compatible with future versions of MATLAB.
-l<file>
For UNIX, link against library lib<file>.
-L<pathname>
For UNIX, include <pathname> in the list of directories to search for libraries.
<name>#<def>
Override options file setting for variable <name>. This option is equivalent to <ENV_VAR>#<val>, which temporarily sets the environment variable <ENV_VAR> to <val> for the duration of the call to mex. <val> can refer to another environment variable by prepending the name of the variable with a $, e.g., COMPFLAGS#"$COMPFLAGS -myswitch".
<name>=<def>
For UNIX, override options file setting for variable <name>.
-O
Build an optimized executable.
-outdir <name>
Place all output files in directory <name>.
-output <name>
Create an executable named <name>. An appropriate executable extension is automatically appended.
-setup
For Windows, set up default options file. This switch should be the only argument passed.
-U<name>
Undefine C preprocessor macro <name>.
-v
Verbose. Print all compiler and linker settings.
-V4
Compile MATLAB 4-compatible MEX-file.

Description

MEX <options> <files> compiles a MEX-function from C or Fortran source code. All nonsource code filenames 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) and mexopts.sh (UNIX).

On UNIX, the options file is written in the Bourne shell script language. The mex script searches for the first occurrence of the options file called mexopts.sh in the following list:

mex uses the first occurrence of the options file it finds. If no options file is found, mex displays an error message. You can directly specify the name of the options file using the -f switch.

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 default options file is placed in your user profile directory after you configure your system by running mex -setup. The mex script searches for the first occurrence of the options file called mexopts.bat in the following list:

mex uses the first occurrence of the options file it finds. If no options file is found, mex searches your machine for a supported C compiler and uses the factory default options file for that compiler. If multiple compilers are found, you are prompted to select one.

No arguments can have an embedded equal sign (=); thus, -DFOO is valid, but -DFOO=BAR is not.


  API Notes The MATLAB Array