Suppress header include for simulink function

조회 수: 6 (최근 30일)
Mario Weyrich
Mario Weyrich 2025년 3월 17일
답변: Akanksha 2025년 6월 13일
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"

답변 (1개)

Akanksha
Akanksha 2025년 6월 13일
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!

카테고리

Help CenterFile Exchange에서 Simulink Coder에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by