Compiles a MEX-function from C or Fortran source code
Syntax
MEX <options> <files>
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 except where noted:
Option
|
Function
|
-argcheck
|
Perform argument checking on MATLAB API functions (C functions only). |
-c
|
Compile only; do not link. |
-D<name>[=<def>]
|
(UNIX and Macintosh) Define C preprocessor macro <name> [as having value <def> .] |
-D<name>
|
(Windows) Define C preprocessor macro <name> . |
-f <file>
|
(UNIX and Windows) Use <file> as the options file; <file> is a full path name if it is not in current directory. . (On Windows, not necessary if you use the -setup option.) |
-f <file>
|
(Macintosh) Use <file> as the options file. (Not necessary if you use the -setup option.) If <file> is specified, it is used as the options file. If <file> is not specified and there is a file called mexopts in the current directory, it is used as the options file. If <file> is not specified and mexopts is not in the current directory and there is a file called mexopts in the directory <matlab>:extern:scripts: , it is used as the options file. Otherwise, an error occurs. |
-F <file>
|
(UNIX) Use <file> as the options file. <file> is searched for in the following manner:
The file that occurs first in this list is used:
· ./<filename> · $HOME/matlab/<filename> · $TMW_ROOT/bin/<filename> |
-F <file>
|
(Windows) Use <file> as the options file. (Not necessary if you use the -setup option.) <file> is searched for in the current directory first and then in the same directory as mex.bat . |
-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. |
-l<file>
|
(UNIX) Link against library lib<file> . |
-L<pathname>
|
(UNIX) Include <pathname> in the list of directories to search for libraries. |
<name>=<def>
|
(UNIX and Macintosh) Override options file setting for variable <name> . |
-n
|
No execute flag. Using this option causes the commands that would be used to compile and link the target to be displayed without executing them. |
-output <name>
|
Create an executable named <name> . (An appropriate executable extension is automatically appended.) |
-O
|
Build an optimized executable. |
-setup
|
(Windows and Macintosh Only) Set up default options file. This switch should be the only argument passed. |
-U<name>
|
(UNIX and Windows) Undefine C preprocessor macro <name> . |
-V4
|
Compile MATLAB 4-compatible MEX-files. |
-v
|
Verbose; print all compiler and linker settings. |
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).
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:
./mexopts.sh
, $HOME/matlab/mexopts.sh
, $MATLAB/bin/mexopts.sh
.
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'
).