User`s guide
Alternative Ways of Compiling M-Files
4-35
Alternative Ways of Compiling M-Files
The previous section showed how to compile main.m and mrank.m separately.
This section explores two other ways of compiling M-files.
Note These two alternative ways of compiling M-files apply to C++ as well as
toCcode;theonlydifferenceisthatyouadd-L cpp for C++.
Compiling MATLAB Provided M-Files Separately
The M-file mrank.m contains a call to rank. The MATLAB Compiler translates
the call to
rank into a C call to mlfRank.ThemlfRank ro utine is p art of the
MATLAB M-File Math Library . The
mlfRank routine behaves in stand-alone
applicatio ns exactly as the
rank function be hav es in the MATLAB i n te rpreter.
However, if t h is default behavior is not des irable, you can create your own
version of
rank or mlfRank.
One way to create a new version of
rank is to copy MATLAB’s own source code
for
rank andthentoeditthiscopy.MATLABimplementsrank as the M-file
rank.m rather than as a bui lt-in command. To see MATLAB’s code for rank.m,
enter
type rank
Copy this code into a file named rank.m located in the same directory as
mrank.m andmain.m.Then,modifyyourversionof rank.m.Aftercompletingthe
modifications, compile
rank.m.
mcc -t rank
Compiling rank.m generates file rank.c, which contains a function named
mlfRank. Then, compile the other M-files composing the stand-alone
application.
mcc -t main.m (produces main.c)
mcc -t mrank.m (produces mrank.c)
mcc -W main main mrank rank.m (produces main_main.c)