How do I use a custom main file in Simulink Coder?

24 visualizzazioni (ultimi 30 giorni)
I would like to incorporate a custom main function into the Simulink Coder build process. 
I have an application for which I pass some command line arguments via a modified version of the default "rt_main.c". 
How can I create a custom main file with the Toolchain approach in Simulink Coder?

Risposta accettata

MathWorks Support Team
MathWorks Support Team il 25 Mar 2025 alle 0:00
Modificato: MathWorks Support Team il 28 Mar 2025 alle 9:57
When using the toolchain approach, you will need to create a "grt_make_rtw_hook.m" file (if you are using Embedded Coder, it will be "ert_make_rtw_hook.m "). You can find more information about how to use build hooks in this documentation. 
To add a main, you need to follow this process:
  1. Copy "ert_make_rtw_hook.m" to a folder in the MATLAB path. Rename it in accordance with the naming conventions. For example, to use it with the GRT target "grt.tlc", rename it to "grt_make_rtw_hook.m".
  2. Rename the "ert_make_rtw_hook" function within the file to match the file name (grt_make_rtw_hook if using Simulink Coder)
  3. In the "after_tlc" stage, use the "setTargetProvidesMain" function as follows: 
    setTargetProvidesMain(buildInfo,true);
Now, you need to use the Configuration Parameters > Code Generation > Custom Code > Source Files field to add your custom "main.c" to the project. When you indicate that the target provides "main.c," the project requires this file to build without errors. 
More related information can be found on the "setTargetProvidesMain" and "addSourceFiles" documentation pages below, referring to functions that could be used in the 'after_tlc' case in the "grt_make_rtw_hook.m" file.
"setTargetProvidesMain" documentation:
"addSourceFiles" documentation:
You can find an example "grt_make_rtw_hook" setting up that functionality attached. 

Più risposte (0)

Categorie

Scopri di più su Simulink Coder in Help Center e File Exchange

Prodotti


Release

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by