| MATLAB Application Program Interface | Search  Help Desk |
| The mex Script |
Compiles a MEX-function from C or Fortran source code
Syntax
MEX <options> <files>
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: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).
Note: The MathWorks provides an option (setup) for the mex script that lets you set up a default options file on Windows systems. See the Application Program Interface Guide for additional information.
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./mexopts.sh,$HOME/matlab/mexopts.sh,$MATLAB/bin/mexopts.sh.
<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 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.