How to resolve code generation errors caused by custom TLC file for custom C++ inlined S-Function within referenced model?

조회 수: 8 (최근 30일)

I have a custom C++ S-Function "sfun_Timestamp.cpp" that I am calling via an "S-Function" block within my Simulink model "Test_Timestamp.slx" in MATLAB R2021b. I am then calling "Test_Timestamp.slx" as a referenced model in "Test_Timestamp_Global.slx". I have written a custom TLC file "sfun_Timestamp.tlc" to inline my custom S-Function.
Simulating the top-level model "Test_Timestamp_Global.slx" that includes the S-Function inside the referenced model "Test_Timestamp.slx" works correctly. However, I observe the following build error when generating C++ code for "Test_Timestamp_Global.slx":

Component:Simulink | Category:Block diagram warning
### Invoking Target Language Compiler on Test_Timestamp.rtw
### Using System Target File: L:\ML_MATLAB64\R2021b\rtw\c\ert\ert.tlc
### Loading TLC function libraries
### Initial pass through model to cache user defined code
Error: File: sfun_Timestamp.tlc Line: 1 Column: 1
A %implements directive must appear within a block template file and must match the %language and type specified
Main program:
==> [00] L:\ML_MATLAB64\R2021b\rtw\c\tlc\blocks\gensfun.tlc:BlockTypeSetup(585)
[01] L:\ML_MATLAB64\R2021b\rtw\c\tlc\private_api\blocksetuplib.tlc:BlockSetupAndCompatibilityCheck(113)
[02] L:\ML_MATLAB64\R2021b\rtw\c\tlc\mw\commonpass.tlc:<NONE>(53)
Error: File: sfun_Timestamp.tlc Line: 1 Column: 1
A %implements directive must appear within a block template file and must match the %language and type specified
Main program:
==> [00] L:\ML_MATLAB64\R2021b\rtw\c\tlc\blocks\gensfun.tlc:BlockInstanceSetup(378)
[01] L:\ML_MATLAB64\R2021b\rtw\c\tlc\private_api\blocksetuplib.tlc:BlockSetupAndCompatibilityCheck(134)
[02] L:\ML_MATLAB64\R2021b\rtw\c\tlc\mw\commonpass.tlc:<NONE>(53)
.
### Caching model source code
Error: File: sfun_Timestamp.tlc Line: 1 Column: 1
A %implements directive must appear within a block template file and must match the %language and type specified
Main program:
==> [00] L:\ML_MATLAB64\R2021b\rtw\c\tlc\blocks\gensfun.tlc:Outputs(1558)
[01] L:\ML_MATLAB64\R2021b\rtw\c\tlc\mw\commentlib.tlc:generateNonExprOutput(178)
[02] L:\ML_MATLAB64\R2021b\rtw\c\tlc\mw\opaquelib.tlc:OpaqueTLCBlockFcn(5025)
[03] L:\ML_WORKSPACE\slprj\ert\Test_Timestamp\tmwinternal\tlc\s1_b0_0zjfs_0_Outputs.tlc:Outputs(7)
[04] L:\ML_MATLAB64\R2021b\rtw\c\tlc\mw\opaquelib.tlc:FcnGenRateGroupedCodeFromModule(5926)
[05] L:\ML_MATLAB64\R2021b\rtw\c\tlc\mw\opaquelib.tlc:FcnGenerateCodeFromModule(5809)
[06] L:\ML_MATLAB64\R2021b\rtw\c\tlc\mw\opaquelib.tlc:SLibFcnGenBodySysFcn(292)
[07] L:\ML_MATLAB64\R2021b\rtw\c\tlc\mw\opaquelib.tlc:SLibFcnGenBodyFcnCache(509)
[08] L:\ML_MATLAB64\R2021b\rtw\c\tlc\mw\opaquelib.tlc:SLibFcnGenBodySysFcnEntry(667)
[09] L:\ML_MATLAB64\R2021b\rtw\c\tlc\mw\commonbodlib.tlc:FcnGenBodySysCache(1900)
[10] L:\ML_MATLAB64\R2021b\rtw\c\tlc\mw\commonbodlib.tlc:SLibGenBodyCache(6478)
[11] L:\ML_MATLAB64\R2021b\rtw\c\tlc\mw\formatwide.tlc:<NONE>(76)
.
Error: File: sfun_Timestamp.tlc Line: 1 Column: 1
A %implements directive must appear within a block template file and must match the %language and type specified
Main program:
==> [00] L:\ML_MATLAB64\R2021b\rtw\c\tlc\blocks\gensfun.tlc:BlockInstanceData(704)
[01] L:\ML_MATLAB64\R2021b\rtw\c\tlc\blocks\subsystm.tlc:BlockInstanceData(35)
[02] L:\ML_MATLAB64\R2021b\rtw\c\tlc\lib\syslib.tlc:LibCacheBlockInstanceData(6667)
[03] L:\ML_MATLAB64\R2021b\rtw\c\tlc\mw\formatwide.tlc:<NONE>(92)
### Writing header file Test_Timestamp_types.h
### Writing header file Test_Timestamp.h
### Writing source file Test_Timestamp.cpp
.
### Writing header file Test_Timestamp_private.h
### TLC code generation complete.
### Build procedure for Test_Timestamp aborted due to an error.

Build Summary

Code generation targets built:

Model Action Rebuild Reason
=================================================================================================
Test_Timestamp Failed Dependency sfun_Timestamp.tlc of S-function sfun_Timestamp has changed.

0 of 2 models built (1 models already up to date)
Build duration: 0h 0m 2.464s

Error: Errors occurred - aborting
How can I resolve this build error and generate code?

채택된 답변

MathWorks Support Team
MathWorks Support Team 2025년 1월 15일
The final error message "Error: Errors occurred - aborting" is generic, but the complete stack trace shows that there are build issues related to the custom TLC file.
You can use the Legacy Code Tool to automatically generate a TLC file for inlined S-Functions. For instance, the Legacy Code Tool can automatically generate a new TLC file for the C++ S-Function "sfun_Timestamp.cpp" by specifying the following options:
% Configure options for the TLC auto-generation def = legacy_code('initialize'); def.Options.language = 'C++'; def.SFunctionName = 'sfun_Timestamp'; % Auto-generate a TLC file "sfun_Timestamp.tlc" for the S-Function legacy_code('sfcn_tlc_generate', def);
For more information on customizing and configuring the options for the auto-generated TLC file, refer to the documentation on the "legacy_code" function.
Please note that you should evaluate whether the auto-generated TLC file via the Legacy Code Tool matches the desired behavior of your custom TLC file.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Target Language Compiler에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by