how do I override rt_main in embedded coder?

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

回答(1 个)

Vandit
Vandit 2023-5-31
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 个评论
serena aiello
serena aiello 2023-10-26
Hi Paul, I want to do the same thing. Do you have find an automatic solution?
Paul
Paul 2023-10-26
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

请先登录,再进行评论。

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by