External Interfaces/API Reference | ![]() ![]() |
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 your system.
|
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:
$HOME/matlab
<MATLAB>/bin
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:
user profile
directory<MATLAB>\bin\win32\mexopts
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 | ![]() |