User`s guide

Mixing M-Files and C or C++
Mixing M-Files and C or C++
In this section...
“Examples Overvie w” on page 6-13
“Simple Example” on page 6-13
“Advanced C Example” on page 6-18
Examples Overview
The examples in this section illustrate how to mix M-files and C o r C++
source code files:
The first example is a simple application that mixes M-files and C code.
The second example illustrates how to write C code that calls a compiled
M-file.
Onewaytocreateastandaloneapplicationistocodesomeofitasoneor
more function M-files and to code other parts directly in C or C++. To write a
standalone application this way, you must know how to do the following:
Call the external C or C++ functions generated by MATLAB Com pile r.
Handle the results these C or C++ functions return.
Note If you include compiled M-code into a larger application, you
must produce a library wrapper file even if you do not actually create a
separate library. For m ore information on creating libraries, see Chapter 7,
“Libraries”.
Simple Example
This example involves mixing M -files and C code. Consider a
simple application whose source code consists of
mrank.m, mrankp.c,
main_for_lib.c,andmain_for_lib.h.
6-13