User`s manual
3 Creating Fortran MEX-Files
3-36
Advanced Topics
These sections cover advanced features of MEX-files that you can use when
your applications require sophisticated MEX-files.
Help Files
Because the MATLAB interpreter chooses the MEX-file when both an M-file
and a MEX-file with the same name are encountered in the same directory, it
is possible to use M-files for documenting the behavior of your MEX-files. The
MATLAB
help command will automatically find and display the appropriate
M-file when help is requested and the interpreter will find and execute the
corresponding MEX-file when the function is actually invoked.
Linking Multiple Files
You can combine several source files when building MEX-files. For example,
mex circle.f square.o rectangle.f shapes.o
is a legal command that operates on the .f and .o files to create a MEX-file
called
circle.ext, where ext is the extension corresponding to the MEX-file
type. The name of the resulting MEX-file is taken from the first file in the list.
You may find it useful to use a software development tool like
MAKE to manage
MEX-file projects involving multiple source files. Simply create a
MAKEFILE
that contains a rule for producing object files from each of your source files and
then invoke
mex to combine your object files into a MEX-file. This way you can
ensure that your source files are recompiled only when necessary.
Note On UNIX, you must use the -fortran switch to the mex script if you are
linking Fortran objects.
Workspace for MEX-File Functions
Unlike M-file functions, MEX-file functions do not have their own variable
workspace.
mexEvalString evaluates the string in the caller’s workspace. In
addition, you can use the
mexGetMatrix and mexPutMatrix routines to get and
put variables into the caller’s workspace.