MATLAB Compiler    

C Shared Library

The MATLAB Compiler allows you to build a shared library from the files created in the previous section, "C Libraries." To build the shared library, libtimefun.ext, in one step, use

This example uses the csharedlib bundle file

The bundle file option, -B <filename>:[<a1>,<a2>,...,<an>], replaces the entire expression on the mcc command line with the contents of the specified file and it allows you to use replacement parameters. This example uses the csharedlib bundle file and replaces the expression

with

giving the new statement

The -t option tells the Compiler to generate C code from each of the listed M-files. The -T link:lib option tells the Compiler to compile and link a shared library. The -h option tells the Compiler to include any other M-functions called from those listed on the mcc command line, i.e., helper functions.

mlib Files

Shared libraries, like libraries, let you compile a common set of functions once and then compile other M-functions that depend on them without compiling them again.You accomplish this using mlib files, which are automatically generated when you generate the shared library.

Creating an mlib File.   When you create a library wrapper file, you also get a .mlib file with the same base name. For example,

creates

The last file, libtimefun.ext, is the shared library file for your platform. For example, on the PC, the shared library is

Using an mlib File.   This example uses two functions, tic and toc, that are in the shared library. Consider a new function, timer, defined as

Prior to mlib files, if you compiled timer using

both tic and toc would be recompiled due to the implicit -h option included in the -m macro. Using mlib files, you would use

At compile time, function definitions for tic and toc are located in the libtimefun.mlib file, indicating that all future references to tic and toc should come from the mlib files's corresponding shared library. When the executable is created, it is linked against the shared library. For example, on the PC, the executable timer.exe is created and it is linked against libtimefun.dll.

An advantage of using mlib files is that the generated code is smaller because some of the code is now located in the shared library.

Restrictions.   


  C Libraries C++ Libraries