Generated code from Simulink has class definition final

조회 수: 6 (최근 30일)
Thomas Belz
Thomas Belz 2023년 4월 25일
답변: Kanishk 2024년 10월 16일
How can I get rid of final within:
// Class declaration for model XXX
class XXX final
{
// public data and function members
public:
code generaded header file?

답변 (1개)

Kanishk
Kanishk 2024년 10월 16일
Hi Thomas,
I understand you are facing an issue with the “final” specifier during code generation in Simulink.
I have faced a similar issue earlier. I did not find any option to remove the “final” specifier in Code generation settings. As a workaround, I have manually deleted this "specifier" from the generated code. You can also make use of post code generation commands to automate that process.
To automate the process of removing the specifier, create a MATLAB function that reads the generated C++ files, searches for the final keyword, removes it, and saves the file.
function removeFinalSpec(buildInfo)
% Get the list of generated files
headerFiles = getIncludeFiles(buildInfo, true, true);
for i = 1:length(headerFiles)
file = headerFiles {i};
fileContent = fileread(fileName);
regexprep(fileContent, 'final', '');
fid = fopen(file, 'w');
fwrite(fid, updatedContent);
fclose(fid);
end
end
Using “PostCodeGenCommand” define a post code generation command, which gets evaluated after generating and writing the code to disk and before generating a makefile.
set_param(model, 'PostCodeGenCommand', 'removeFinalSpec(buildInfo)');
To learn more about customizing after code generation, please go through this following official MATLAB documentation.
Thanks
Hope this helps

카테고리

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

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by