Main Content

Interface to a Development Computer Simulator By Using a Shared Library

This example generates a shared library for interfacing to a simulator that runs on your development computer. Generate the shared library by using the system target file ert_shrlib.tlc.

To build a shared library from the model and use the library in an application:

1. Develop your model. For this example, open the model rtwdemo_shrlib. Save a copy of the model to a writable location.

open_system('rtwdemo_shrlib');

The model is a single-rate, discrete-time model. An 8-bit counter feeds the triggered subsystem named Amplifier. Parameters INC, LIMIT, and RESET are set to constant values 1, 4, and 0, respectively. When signal equal_to_count is true, the subsystem amplifies its input signal by a gain factor K=3 and the output signal is updated.

2. Open the Embedded Coder app.

3. Set model configuration parameter System target file to ert_shrlib.tlc.

4. Build the shared library file. The file that the code generator produces depends on your development platform. For example, on a Windows system, the code generator produces the library file rtwdemo_shrlib_win64.dll.

5. Create application code that uses the shared library. This example uses application code that is available in these files:

matlabroot\toolbox\rtw\rtwdemos\shrlib_demo\rtwdemo_shrlib_app.h matlabroot\toolbox\rtw\rtwdemos\shrlib_demo\rtwdemo_shrlib_app.c

To view the source code in these files, in the model, click the white buttons for the .h and .c files.

6. Compile and link the file application and shared library files to produce an executable program. The following script compiles, builds, and runs the program.

matlabroot\toolbox\rtw\rtwdemos\shrlib_demo\run_rtwdemo_shrlib_app.m

To view the script code, in the model, click the white button for the .m file.

To build the model and run the application that uses the generated shared library, in the model, double-click the blue button.

For more information about using a shared library, see Package Generated Code as Shared Libraries (Embedded Coder).

Related Topics