reusable simulink functions prototype
5 views (last 30 days)
Show older comments
Hello,
I am trying to use reusable simulink functions, and have the functions calls in different referenced models. But when generating c code I get:
Function caller prototype '' is not compatible with function definition.
I put the simulink function declaration in a referenced model "Model_B", but the function definition:
extern real_T Model_B_timestwo(RT_MODEL_Model_B_T * const Model_B_M, const real_T rtu_u);
doesn't match with the called function prototype:
extern real_T Model_B_timestwo(const real_T rtu_u);
This information is missing from the function call: the real time model data structure, and the pointer to the structure. How do I let the function caller know that the function called is a reusable one ? and that he shoulf include an entry point to it?
Best regards.
0 Comments
Answers (1)
sanidhyak
on 1 Sep 2025
I understand that you are trying to use reusable Simulink functions across different referenced models. When generating the C code, the issue which you faced usually occurs because by default, a referenced model generates a model data structure argument “(RT_MODEL_*)” in the function definition:
extern real_T Model_B_timestwo(RT_MODEL_Model_B_T * const Model_B_M, const real_T rtu_u);
while the caller expects a simpler reusable prototype:
extern real_T Model_B_timestwo(const real_T rtu_u);
The mismatch actually arises due to model reference interface settings and function packaging options.
To resolve this, kindly follow the steps below:
1. Open your referenced model (“Model_B”)
2. Go to Code Mappings > Functions
3. For your Simulink Function (“timestwo”), set:
- “Function Packaging = Reusable function”
4. In Model Settings (Ctrl+E) > Code Generation > Interface:
- Set Code interface packaging = Reusable function
- Disable "Pass root-level I/O as structure reference"
- Disable "Use model data structure"
5. In Code Mappings > Inports/Outports:
- Set storage class to Auto or ExportedGlobal
6. Now, regenerate code. The new generated prototype will be:
extern real_T Model_B_timestwo(const real_T rtu_u);
matching the caller function signature and hence resolving the incompatibility.
Kindly refer to the following official documentation for more details:
Cheers & Happy Modeling!
0 Comments
See Also
Categories
Find more on Simulink Functions in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!