Avoid generating empty functions with Simulink Embedded Coder

13 次查看(过去 30 天)
Hi, I'm generating C code from a Simulink model using Embedded Coder on Matlab R2017a. By default two functions are created, step and initialize. For my Simulink model, the initalize function is empty. Is there a way of avoiding generating the initialize function if it is going to be empty? The generation of this empty function creates some problems on the postprocessing of the generated C code by another tool so I was wondering if I could configure Embedded Coder not to generate empty functions.
Thanks in advance.

回答(1 个)

Kanishk
Kanishk 2025-1-21
编辑:Kanishk 2025-1-21
When generating C code from a Simulink model using Embedded Coder, the code generation process typically includes the “initialize”, “step” and “terminate” functions. However, if one of these functions is empty, there is currently no option to stop it from generating as Simulink mostly generates these functions as part of boiler plate code.
During the build process, “gcc” handles and removes the empty functions automatically as part of optimizations. You can also add custom optimization flags such ‘-O3’ in Simulink using ‘SimCustomCompilerFlags’.
set_param(gcs, 'SimCustomCompilerFlags', '-O3')
If possible, You can then safely remove any check for identifying empty functions from the tool you are using.
A workaround for removing empty functions from generated code can be using a post-processing script. Empty functions can be identified using regular expressions and can be removed. All files are needed to be examined by the script to remove the function calls and function definitions from header files.
You can access the documentation for adding Custom compiler flags and using regular expressions in MATLAB using the following commands.
web(fullfile(docroot, 'simulink/gui/compiler-flags.html'))
web(fullfile(docroot, 'matlab/matlab_prog/regular-expressions.html'))

类别

Help CenterFile Exchange 中查找有关 Deployment, Integration, and Supported Hardware 的更多信息

产品


版本

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by