Generated code from Simulink has class definition final
6 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
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
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Deployment, Integration, and Supported Hardware 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!