External Interfaces/API    

Custom Building on UNIX

On UNIX systems, there are two stages in MEX-file building: compiling and linking.

Compile Stage

The compile stage must:

Link Stage

The link stage must:

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).

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.

Variable
C Compiler
Fortran Compiler
Linker
Executable
CC
FC
LD
Flags
CFLAGS
FFLAGS
LDFLAGS
Optimization
COPTIMFLAGS
FOPTIMFLAGS
LDOPTIMFLAGS
Debugging
CDEBUGFLAGS
FDEBUGFLAGS
LDDEBUGFLAGS
Additional libraries
CLIBS
FLIBS
----

For specifics on the default settings for these variables, you can:


  Default Options File on Windows Custom Building on Windows