Generated code from Simulink has class definition final
7 views (last 30 days)
Show older comments
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?
0 Comments
Answers (1)
Kanishk
on 16 Oct 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
0 Comments
See Also
Categories
Find more on Deployment, Integration, and Supported Hardware in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!