MATLAB Compiler    

C Libraries

The intent of the C library wrapper files is to allow the inclusion of an arbitrary set of M-files into a static library or shared library. The header file contains all of the entry points for all of the compiled M functions. The export list contains the set of symbols that are exported from a C shared library.

Another benefit of creating a library is that you can compile a common set of functions once. You can then compile other M-functions that depend on them without recompiling the original functions. You can accomplish this using mlib files, which are automatically generated when you generate the library. For more information about mlib files, see mlib Files.

This example uses several functions from the toolbox\matlab\timefun directory (weekday, date, tic, calendar, toc) to create a library wrapper. The -W lib:libtimefun -L C options produce the files shown in this table.

File
Description
libtimefun.c
C wrapper file
libtimefun.h
C header file
libtimefun.exports
C export list
libtimefun.mlib
M-file library

libtimefun.c

The C wrapper file (libtimefun.c) contains the initialization (libtimefunInitialize) and termination (libtimefunTerminate) functions for the library. You must call libtimefunInitialize before you call any Compiler-generated code. This function initializes the state of Compiler-generated functions so that those functions can be called from C code not generated by the Compiler. You must also call libtimefunTerminate before you unload the library.

The library files in this example are produced from the command


  Simulink S-Functions C Shared Library