User`s guide

Uses of the Compiler
1-7
Uses of the Compiler
The MATLAB Compiler (mcc) can translate M-files into C f iles. The r esultant
C files can be used in any of the supported executable types including MEX,
executable, or library bygenerating an appropriat e wrapperfile.Awrapper file
contains the required interface between t he C ompiler-generated code and a
supported executable type. For e xample, a M EX wrapper contains the MEX
gateway routine that sets up the left- and right-hand arguments for invoking
the Compiler-generated code.
The code produced by the MATLAB Compiler is independent of the final target
type MEX, executable, or library. T he wrapper file provides the necessary
interface to t he t arg et type.
Note MEX-file s g e n erat e d b y the MATLAB Compil er 2.1 are not backward
compatible. They requi re MATLAB 6/Release 12 or g re ater.
Creating MEX-Files
The MATLAB Compiler, when invoked with the -x macro option, produces a
MEX-file from M-files. The Compiler:
1 Translates your M code to C code.
2 GeneratesaMEXwrapper.
3 Invokes the mex utility which builds the C MEX-file source into a MEX-file
by linking the MEX-file with t he MEX versio n of the math libraries
(
libmatlbmx).
This figure illustrates the process of producing a MEX-file. The MATLAB
interpreter dynamically loads MEX-files as they are needed. Some MEX-files
run significantly faster than their M-file equivalents, which is explained in
“Faster Execution” on page 1-14.