How do I prevent the rt_main.c or ert_main.c file from being included in the packNGo package when using ert.tlc?
17 views (last 30 days)
Show older comments
MathWorks Support Team
on 27 Feb 2019
Edited: MathWorks Support Team
on 19 Aug 2024 at 14:54
We're generating code from Simulink using our own custom target which is based on the ERT target. Often, we like to create a ZIP of our generated code (and all necessary files for compilation) that can be provided to another team who might not have MATLAB (or the same version) installed on their system.
In our target, we create our own "main" source file and function to wrap the functions (e.g., init, output, etc.) in the generated <model_name>.c source file. However, when we use the packaging routines, we've found that it always seems to include the rt_main.c or ert_main.c (depending upon which version of MATLAB is used) source files from the MATLAB_ROOT directory. This file isn't needed nor used in the compilation as we have our own. We have already turned off the option to generate example main function (setting the Configuration Parameters > Code Generation > Templates > Generated an example main program parameter value to 'off').
I've looked in the buildInfo, and found that the rt_main.c or ert_main.c source files are listed automatically. Is there a way to disable these from being included?
Accepted Answer
MathWorks Support Team
on 19 Aug 2024 at 0:00
Edited: MathWorks Support Team
on 19 Aug 2024 at 14:54
Background Information on the "main" files
When the model configuration parameter "Generate an example main program" is selected, an example main program module (ert_main.c or .cpp) is generated. When "Generate an example main program" is not selected, a static main program module (rt_main.c or rt_main.cpp) is generated as an example or template for developing the embedded application. Either way, one of these files is captured in the buildInfo.mat file that "packNGo" uses to find the necessary files to include.
Deploy Applications to Target Hardware (section "Static Main Program Module"): https://www.mathworks.com/help/ecoder/ug/standalone-programs-no-operating-system.html#f13018
Solution
Since the "packNGo" function uses the buildInfo.mat to find all the files to include, we can control which files are included by modifying the buildinfo.mat file. The attached "removeExampleMain.m" will remove main files ('rt_main' or 'ert_main') from the buildInfo.mat file. When passing the modified buildInfo.mat to "packNGo", make sure there are no other buildInfo.mat files presented in the current working directory. An old buildInfo.mat could shadow the modified buildInfo.mat and be used by "packNGo" instead.
The "removeExampleMain.m" function can be called automatically using the "Post code generation command" model configuration parameter or manually before "packNGo" is used.
Customize Post-Code-Generation Build Processing: https://www.mathworks.com/help/releases/R2024a/ecoder/ug/customizing-post-code-generation-build-processing.html
0 Comments
More Answers (0)
See Also
Categories
Find more on Simulink Coder 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!