MATLAB Application Program Interface | Search  Help Desk |
The mex Script |
Compiles a MEX-function from C or Fortran source code
MEX <options> <files>All non-source code file names passed as arguments are passed to the linker without being compiled. These options are available on all platforms except where noted:
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).
Note: The MathWorks provides an option (setup
) for the mex
script that lets you set up a default options file on Windows and Macintosh 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 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'
).