MATLAB: How to include a custom library in the generated code instead of the original library that Stateflow Coder includes

codecustomgeneratedlibrarystateflowStateflow Coder

I would like to include a custom library in the generated code instead of the original library that Stateflow Coder includes.

Best Answer

Follow the steps below to include your custom library instead of the original library:
1. If you want to replace the call to 'math.h' and replace it with your custom library 'mymath.h', open up 'math.h' privided by the compiler and look for an include guard such as that shown below.
The Microsoft provided 'math.h' contains the include guard:
#ifndef _INC_MATH
#define _INC_MATH
......
On UNIX, the include guard is as follows:
#ifndef _MATH_H
#define _MATH_H
.....
2. To customize the code generated by the Stateflow target, go to Tools => RTW Target from the Stateflow chart. Now click on the 'Target Options..' button. This will bring up a window which says "Custom Code included at the top of the generated code" at the top of a pull-down menu.
In this window, insert a #define of this include guard:
#define _INC_MATH
This tells the preprocessor not to include 'math.h' from the compiler.
Refer to the Related Solution for information on how to integrate custom C code into Stateflow.