How to avoid duplicate functions in generated code with embedded coder?

7 views (last 30 days)
The simulink model control_model has a certain library lib_i_boolean which is set to by a reusable function (subsystem properties -> treat as atomic unit, code generation function packaging -> reusable function). This library is used dozens of times in control_model.
Now, the embedded coder generates the following files:
  • control_model_lib_i_boolean.c
  • control_model_lib_i_boolean.h
  • control_model_lib_i_boolean_d.c
  • control_model_lib_i_boolean_d.h
  • control_model_lib_i_boolean_f.c
  • control_model_lib_i_boolean_f.h
  • control_model_lib_i_boolean_g.c
  • control_model_lib_i_boolean_g.h
  • control_model_lib_i_boolean_i.c
  • control_model_lib_i_boolean_i.h
  • control_model_lib_i_boolean_m.c
  • control_model_lib_i_boolean_m.h
  • control_model_lib_i_boolean_n.c
  • control_model_lib_i_boolean_n.h
We want to avoid these duplicate files, so only have
  • control_model_lib_i_boolean.c
  • control_model_lib_i_boolean.h
The internet provided a half answer, see: , which seems to be applicable for matlab code only?
We already did the following:
  • Checked number of input or output variables --> always 6 inputs and 5 outputs, although some outputs are connected to terminators
  • Checked type of input or output variables --> always the same datatype (5 boolean inputs, 1 single)
  • Checked size of input or output variables --> always the same size (scalar, dimension 1)
  • Checked values of input variables --> different constants are connected to the inputs
  • Searched the model configuration for an "coder.ignoreConst" parameter
We're suspecting it has to do with using different constants as inputs and/or output terminators, so the compiler wants to optimize the function reuse. We want to tell the compiler to stop doing that, or change the simulink model such that the compiler stops doing this.
We're using embedded coder in R2016b, R2019b and R2020b.
Thanks for the help, much appreciated.

Answers (1)

Jesús Zambrano
Jesús Zambrano on 4 Aug 2021
Apart from setting the function packaging to 'Reusable function', could you set the Function name option to 'User specified' and then set Function name as you prefer. Set this to all the exact copies of your subsystem in the model.
Hope it helps.


Find more on Deployment, Integration, and Supported Hardware in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!