User`s guide
4 Stand-Alone Applications
4-40
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
to C code; the only difference is that you add -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. The mlfRank routine is part of the
MATLAB M-File Math Library. The
mlfRank routine behaves in stand-alone
applications exactly as the
rank function behaves in the MATLAB interpreter.
However, if this default behavior is not desirable, you can create your own
version of
rank or mlfRank.
One way to create a new version of
rank is to copy the MATLAB source code for
rank and then to edit this copy. MATLAB implements rank as the M-file
rank.m rather than as a built-in command. To see the MATLAB code for
rank.m, enter
type rank
Copy this code into a file named rank.m located in the same directory as
mrank.m and main.m. Then, modify your version of rank.m. After completing the
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)
To compile and link all four C source code files (
main.c, rank.c, mrank.c, and
main_main.c) into a stand-alone application, use