Why does Simulink code generator put #includes into my .c AND into the also #included .h?

조회 수: 4 (최근 30일)
I generate C code from a Simulink model. Since upgrading from 2021a to 2023b, I've noticed that Simulink redundantly #includes my _sharedutils headers containing function declarations both in myModelName.c AND in myModelName.h, even though it also #includes myModelName.h in myModelName.c.
Can anybody tell me why it would do that and how to make it stop?

답변 (1개)

Infinite_king
Infinite_king 2023년 12월 11일
편집: Infinite_king 2023년 12월 11일
Hi Simon Ahrens,
I understand that after upgrading to R2023b, C code generated from Simulink model contains unnecessary header files located in ‘my_sharedutils’ folder.
In Simulink, we can create models that can be reused in other models multiple times. Starting in R2022b, the code generator handles function and file packaging of generated code differently. For reusable library subsystems, the code generator produces subsystem code in the ‘slprj/target/_sharedutils’ folder. The subsystem code is shared across models as per model reference hierarchy.
This is indeed a valuable feature that helps minimize redundancy. You have the flexibility to control the names of functions, files, and the location of the shared library code, allowing you to customize it according to your needs. For more information on customization and setting up reusable library code, please refer to the following MATLAB documentation,
For more information on changes in each release, refer the following MATLAB documentation,
Hope this is helpful.
  댓글 수: 1
Simon Ahrens
Simon Ahrens 2023년 12월 12일
Hi Infinite_king,
thanks for your reply. I'm fine with how reusable library subsystems work in general. That being said, my issue is regarding function-call subsystems. In 2023b, their block parameters don't even show the checkbox for "Treat as an atomic unit" so I can't control function packaging in the Code Generation tab.
For each of these functions/subsystems, Simulink generates a .h in slprj/ert/_sharedutils (it does not give me a slprj/target subdirectory) with the function declaration like this:
extern void semSetSndSetID(uint8_T rtu_u);
Which is fine. The function is defined in the main .c file:
/* Output function */
void semSetSndSetID(uint8_T rtu_u)
{
int32_T i;
int32_T tmp;
...
Which is also fine.
What's weird to me is that the main .c file ("x.c") #includes both the main header ("x.h") AND the function subsystem header from slprj/ert/_sharedutils like this:
#include "x.h"
#include "x_types.h"
#include "semSetSndSetID.h"
while the main .h file ("x.h") ALSO #includes it:
#include "x_types.h"
#include "semSetSndSetID.h"
Here, I would expect x.c to only include x.h and x.h to include all the sharedutils headers.

댓글을 달려면 로그인하십시오.

카테고리

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

제품


릴리스

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by