External Interfaces/API |
On UNIX systems, there are two stages in MEX-file building: compiling and linking.
Compile Stage
<matlab>/extern/include
to the list of directories in which to find header files (-I<matlab>/extern/include
)
MATLAB_MEX_FILE
(-DMATLAB_MEX_FILE
)
<matlab>/extern/src/mexversion.c
Link Stage
mexversion.c
)
<matlab>/extern/lib/$Arch/version4.o
mexFunction
and mexVersion
(these symbols represent functions called by MATLAB)
For Fortran MEX-files, the symbols are all lower case and may have appended underscores. For specific information, invoke the mex
script in verbose mode and examine the output.
Build Options
For customizing the build process, you should modify the options file. The options file contains the compiler-specific flags corresponding to the general steps outlined above. The options file consists of a series of variable assignments; each variable represents a different logical piece of the build process. The options files provided with MATLAB are located in <matlab>/bin
. The section, Default Options File on UNIX, describes how the mex
script looks for an options file.
To aid in providing flexibility, there are two sets of options in the options file that can be turned on and off with switches to the mex
script. These sets of options correspond to building in debug mode and building in optimization mode. They are represented by the variables DEBUGFLAGS
and OPTIMFLAGS
, respectively, one pair for each driver that is invoked (CDEBUGFLAGS
for the C compiler, FDEBUGFLAGS
for the Fortran compiler, and LDDEBUGFLAGS
for the linker; similarly for the OPTIMFLAGS
).
mex
script will include the OPTIMFLAGS
options in the compile and link stages.
mex
script will include the DEBUGFLAGS
options in the compile and link stages, but will not include the OPTIMFLAGS
options.
mex
script (-O
and -g
, respectively).
Aside from these special variables, the mex
options file defines the executable invoked for each of the three modes (C compile, Fortran compile, link) and the flags for each stage. You can also provide explicit lists of libraries that must be linked in to all MEX-files containing source files of each language.
The variables can be summed up as follows.
For specifics on the default settings for these variables, you can:
<matlab>/bin/mexopts.sh
(or the options file you are using), or
mex
script in verbose mode
Default Options File on Windows | Custom Building on Windows |