필터 지우기
필터 지우기

how do I override rt_main in embedded coder?

조회 수: 8 (최근 30일)
Paul
Paul 2023년 5월 25일
댓글: Paul 2023년 10월 26일
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

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Deployment, Integration, and Supported Hardware에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by