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 次查看(过去 30 天)
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? 

采纳的回答

MathWorks Support Team
MathWorks Support Team 2024-8-19,0:00
编辑:MathWorks Support Team 2024-8-19,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. 

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Simulink Coder 的更多信息

产品


版本

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by