Generated code from Simulink has class definition final

6 visualizaciones (últimos 30 días)
Thomas Belz
Thomas Belz el 25 de Abr. de 2023
Respondida: Kanishk el 16 de Oct. de 2024
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?

Respuestas (1)

Kanishk
Kanishk el 16 de Oct. de 2024
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

Categorías

Más información sobre Deployment, Integration, and Supported Hardware en Help Center y File Exchange.

Productos


Versión

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by