Suppress header include for simulink function

5 views (last 30 days)
How is it possible to suppress header include for a simulink function called via a s-function block?
For example, following c-s-function code, will automatically generate an #include "Crc_CalculateCRC16.h" in model.h, what is not intended.
if(!ssQuerySimulinkFunction(S, "Crc_CalculateCRC16",SS_SIMULINK_FUNCTION_QUERY_IS_DECLARED)) {
/* Declare the external function as Crc*/
ssDeclareSimulinkFunction(S, fcnPrototype, NULL, SS_GLOBAL_VISIBILITY); /* "Crc" instead of NULL will gen #include "Crc.h" */
How can I suppress this?
ssDeclareSimulinkFunction(S, fcnPrototype, "Crc", SS_GLOBAL_VISIBILITY); -> will generate an #include "Crc.h", but then I am running into issues for model simulation where it then errors out with "Two blocks defining same function. Function names must be unique"

Answers (1)

Akanksha
Akanksha on 13 Jun 2025
The issue you're encountering where ssDeclareSimulinkFunction causes Simulink to automatically generate an #include directive in model, is a known behaviour when using Simulink Functions in S-Function blocks.
You can suppress the automatic header inclusion by Passing NULL as the third argument inssDeclareSimulinkFunction:
ssDeclareSimulinkFunction(S,fcnPrototype,NULL,SS_GLOBAL_VISIBILITY);
This avoids generating #include "Crc.h".
If you use the same function name in multiple blocks, Simulink will throw an error like:
Two blocks defining same function. Function names must be unique.
To avoid name conflicts:
  • Ensure that each Simulink Function block has a unique name, even if they call the same underlying C function.
  • Or, refactor your model to use a single Simulink Function block and call it from multiple places.
Attached is the link to official documentation that backs the workaround suggested. Kindly go through it for further query :
To call a Simulink function outside of the model hierarchy with non-default argument specifications, use ssDeclareSimulinkFunction to declare the Simulink function with NULL function pointer before using other macros to specify the arguments.”
This supports the workaround of using NULL to suppress automatic header inclusion, which indirectly helps avoid name conflicts when multiple blocks declare the same function.
Hope this helps!

Categories

Find more on Simulink Coder in Help Center and File Exchange

Products


Release

R2022a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!