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

4 visualizaciones (últimos 30 días)
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?

Respuestas (1)

Infinite_king
Infinite_king el 11 de Dic. de 2023
Editada: Infinite_king el 11 de Dic. de 2023
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 comentario
Simon Ahrens
Simon Ahrens el 12 de Dic. de 2023
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.

Iniciar sesión para comentar.

Categorías

Más información sobre Simulink Coder en Help Center y File Exchange.

Productos


Versión

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by