Effacer les filtres
Effacer les filtres

how do I override rt_main in embedded coder?

8 vues (au cours des 30 derniers jours)
Paul
Paul le 25 Mai 2023
Commenté : Paul le 26 Oct 2023
Using embedded coder to generate code, I want to exclude rt_main.c from the build and use my own customized version (since the one that gets included does not actually run any of my code). I see that I can generate an example main program (ert_main.c) but I don't see how I can incorporate my customized version of that file into the build. I can add my own main function to the build, but then I get a linker error because main is defined twice. How do I write a customized main function?

Réponses (1)

Vandit
Vandit le 31 Mai 2023
Hi,
To modify main function ‘ert_main.c’, you can navigate to ‘Model_Name_ert_rtw’ folder and customize ‘ert_main.c’ file as per your requirements.
Now to generate a new executable, please refer to the steps shown below:
1. Inside the ‘Model_Name_ert_rtw’ folder, delete all ‘.obj’ files.
2. Delete the already existing ‘Model_Name.exe’ file from your current working directory.
3.Run the ‘Model_Name.bat’ file by running the command ‘!Model_Name.bat’ in the command window to generate the executable again.
Hope this helps.
Thankyou
keep important terms inside quotes [Sd1]
  3 commentaires
serena aiello
serena aiello le 26 Oct 2023
Hi Paul, I want to do the same thing. Do you have find an automatic solution?
Paul
Paul le 26 Oct 2023
Yes, something like this should work in your ert_make_rtw_hook.m
function grt_make_rtw_hook(hookMethod, ...
modelName, ...
rtwroot, ...
templateMakefile, ...
buildOpts, ...
buildArgs, ...
buildInfo) %#ok<INUSL,INUSD>
switch hookMethod
case 'before_make'
% Called after code generation is complete, and just prior to kicking
% off make process (assuming code generation only is not selected.) All
% arguments are valid at this stage.
%sldiagviewer.reportInfo(getFullFileList(buildInfo));
buildInfo.Src.Files.FileName
index = find(strcmp({buildInfo.Src.Files.FileName}, 'rt_main.c'))
if (length(index) > 0)
rt_main = buildInfo.Src.Files(index)
rt_main.FileName = 'main.c';
firstFile = buildInfo.Src.Files(1)
rt_main.Path = fileparts(firstFile.Path);
end
end

Connectez-vous pour commenter.

Catégories

En savoir plus sur Deployment, Integration, and Supported Hardware dans Help Center et File Exchange

Produits


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by