- 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.
Suppress header include for simulink function
조회 수: 6 (최근 30일)
이전 댓글 표시
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"
댓글 수: 0
답변 (1개)
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 in ssDeclareSimulinkFunction:
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:
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!
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!