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!