User`s guide

7 Libraries
Using C/C++ Shared Libraries on Mac OS X
To use a MATLAB Compiler generated library on Mac O S X, you must create
a separat e thread tha t initializes th e shared library and call that library’s
functions. The main thread of your application must create and execute a
CFRunLoop. The main thread of the application is the thread that calls your
driver program’s
main() function. The body of your main () function must do
two things:
Create a new thread, passing to it the address of a thread-function
containing the library initialization and necessary calls to the shared
library g enerated by MATLAB Compiler.
Initialize and start a
CFRunLoop by calling CFR unLoopRun().
The new thread does the main work of the application, including calling
MATLAB Compiler generated libraries, while the main thread is devoted
to the
CFRunLoop.
Note You must be familiar w ith the Mac OS X CFRunLoop object. Consult the
Mac OS X Core Foundation Reference for a detailed discussion on run l oops
and event-driven programming on Mac OS X.
The following ex ample illustrates this procedure. This e xample rewrites the
C shared library example from this chapter for use on Mac OS X. Follow the
same procedure as in the earlier exam ple to build and run this application.
/*=============================== ===============================
*
* MATRIXDRIVER.C Sample driver code that calls the shared
* library created using MATLAB Compiler. Refer to the
* documentation of MATLAB Compiler for more informat ion
* on this
*
* This is the wrapper C code to call a shared library created
* using MATLAB Compiler.
*
* Copyright 1984-2005 The MathWorks, Inc.
7-32