How to resolve code generation errors caused by custom TLC file for custom C++ inlined S-Function within referenced model?
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_MATLAB64R2021brtwcertert.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_MATLAB64R2021brtwctlcblocksgensfun.tlc:BlockTypeSetup(585)
[01] L:ML_MATLAB64R2021brtwctlcprivate_apiblocksetuplib.tlc:BlockSetupAndCompatibilityCheck(113)
[02] L:ML_MATLAB64R2021brtwctlcmwcommonpass.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_MATLAB64R2021brtwctlcblocksgensfun.tlc:BlockInstanceSetup(378)
[01] L:ML_MATLAB64R2021brtwctlcprivate_apiblocksetuplib.tlc:BlockSetupAndCompatibilityCheck(134)
[02] L:ML_MATLAB64R2021brtwctlcmwcommonpass.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_MATLAB64R2021brtwctlcblocksgensfun.tlc:Outputs(1558)
[01] L:ML_MATLAB64R2021brtwctlcmwcommentlib.tlc:generateNonExprOutput(178)
[02] L:ML_MATLAB64R2021brtwctlcmwopaquelib.tlc:OpaqueTLCBlockFcn(5025)
[03] L:ML_WORKSPACEslprjertTest_Timestamptmwinternaltlcs1_b0_0zjfs_0_Outputs.tlc:Outputs(7)
[04] L:ML_MATLAB64R2021brtwctlcmwopaquelib.tlc:FcnGenRateGroupedCodeFromModule(5926)
[05] L:ML_MATLAB64R2021brtwctlcmwopaquelib.tlc:FcnGenerateCodeFromModule(5809)
[06] L:ML_MATLAB64R2021brtwctlcmwopaquelib.tlc:SLibFcnGenBodySysFcn(292)
[07] L:ML_MATLAB64R2021brtwctlcmwopaquelib.tlc:SLibFcnGenBodyFcnCache(509)
[08] L:ML_MATLAB64R2021brtwctlcmwopaquelib.tlc:SLibFcnGenBodySysFcnEntry(667)
[09] L:ML_MATLAB64R2021brtwctlcmwcommonbodlib.tlc:FcnGenBodySysCache(1900)
[10] L:ML_MATLAB64R2021brtwctlcmwcommonbodlib.tlc:SLibGenBodyCache(6478)
[11] L:ML_MATLAB64R2021brtwctlcmwformatwide.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_MATLAB64R2021brtwctlcblocksgensfun.tlc:BlockInstanceData(704)
[01] L:ML_MATLAB64R2021brtwctlcblockssubsystm.tlc:BlockInstanceData(35)
[02] L:ML_MATLAB64R2021brtwctlclibsyslib.tlc:LibCacheBlockInstanceData(6667)
[03] L:ML_MATLAB64R2021brtwctlcmwformatwide.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?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_MATLAB64R2021brtwcertert.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_MATLAB64R2021brtwctlcblocksgensfun.tlc:BlockTypeSetup(585)
[01] L:ML_MATLAB64R2021brtwctlcprivate_apiblocksetuplib.tlc:BlockSetupAndCompatibilityCheck(113)
[02] L:ML_MATLAB64R2021brtwctlcmwcommonpass.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_MATLAB64R2021brtwctlcblocksgensfun.tlc:BlockInstanceSetup(378)
[01] L:ML_MATLAB64R2021brtwctlcprivate_apiblocksetuplib.tlc:BlockSetupAndCompatibilityCheck(134)
[02] L:ML_MATLAB64R2021brtwctlcmwcommonpass.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_MATLAB64R2021brtwctlcblocksgensfun.tlc:Outputs(1558)
[01] L:ML_MATLAB64R2021brtwctlcmwcommentlib.tlc:generateNonExprOutput(178)
[02] L:ML_MATLAB64R2021brtwctlcmwopaquelib.tlc:OpaqueTLCBlockFcn(5025)
[03] L:ML_WORKSPACEslprjertTest_Timestamptmwinternaltlcs1_b0_0zjfs_0_Outputs.tlc:Outputs(7)
[04] L:ML_MATLAB64R2021brtwctlcmwopaquelib.tlc:FcnGenRateGroupedCodeFromModule(5926)
[05] L:ML_MATLAB64R2021brtwctlcmwopaquelib.tlc:FcnGenerateCodeFromModule(5809)
[06] L:ML_MATLAB64R2021brtwctlcmwopaquelib.tlc:SLibFcnGenBodySysFcn(292)
[07] L:ML_MATLAB64R2021brtwctlcmwopaquelib.tlc:SLibFcnGenBodyFcnCache(509)
[08] L:ML_MATLAB64R2021brtwctlcmwopaquelib.tlc:SLibFcnGenBodySysFcnEntry(667)
[09] L:ML_MATLAB64R2021brtwctlcmwcommonbodlib.tlc:FcnGenBodySysCache(1900)
[10] L:ML_MATLAB64R2021brtwctlcmwcommonbodlib.tlc:SLibGenBodyCache(6478)
[11] L:ML_MATLAB64R2021brtwctlcmwformatwide.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_MATLAB64R2021brtwctlcblocksgensfun.tlc:BlockInstanceData(704)
[01] L:ML_MATLAB64R2021brtwctlcblockssubsystm.tlc:BlockInstanceData(35)
[02] L:ML_MATLAB64R2021brtwctlclibsyslib.tlc:LibCacheBlockInstanceData(6667)
[03] L:ML_MATLAB64R2021brtwctlcmwformatwide.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? 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_MATLAB64R2021brtwcertert.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_MATLAB64R2021brtwctlcblocksgensfun.tlc:BlockTypeSetup(585)
[01] L:ML_MATLAB64R2021brtwctlcprivate_apiblocksetuplib.tlc:BlockSetupAndCompatibilityCheck(113)
[02] L:ML_MATLAB64R2021brtwctlcmwcommonpass.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_MATLAB64R2021brtwctlcblocksgensfun.tlc:BlockInstanceSetup(378)
[01] L:ML_MATLAB64R2021brtwctlcprivate_apiblocksetuplib.tlc:BlockSetupAndCompatibilityCheck(134)
[02] L:ML_MATLAB64R2021brtwctlcmwcommonpass.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_MATLAB64R2021brtwctlcblocksgensfun.tlc:Outputs(1558)
[01] L:ML_MATLAB64R2021brtwctlcmwcommentlib.tlc:generateNonExprOutput(178)
[02] L:ML_MATLAB64R2021brtwctlcmwopaquelib.tlc:OpaqueTLCBlockFcn(5025)
[03] L:ML_WORKSPACEslprjertTest_Timestamptmwinternaltlcs1_b0_0zjfs_0_Outputs.tlc:Outputs(7)
[04] L:ML_MATLAB64R2021brtwctlcmwopaquelib.tlc:FcnGenRateGroupedCodeFromModule(5926)
[05] L:ML_MATLAB64R2021brtwctlcmwopaquelib.tlc:FcnGenerateCodeFromModule(5809)
[06] L:ML_MATLAB64R2021brtwctlcmwopaquelib.tlc:SLibFcnGenBodySysFcn(292)
[07] L:ML_MATLAB64R2021brtwctlcmwopaquelib.tlc:SLibFcnGenBodyFcnCache(509)
[08] L:ML_MATLAB64R2021brtwctlcmwopaquelib.tlc:SLibFcnGenBodySysFcnEntry(667)
[09] L:ML_MATLAB64R2021brtwctlcmwcommonbodlib.tlc:FcnGenBodySysCache(1900)
[10] L:ML_MATLAB64R2021brtwctlcmwcommonbodlib.tlc:SLibGenBodyCache(6478)
[11] L:ML_MATLAB64R2021brtwctlcmwformatwide.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_MATLAB64R2021brtwctlcblocksgensfun.tlc:BlockInstanceData(704)
[01] L:ML_MATLAB64R2021brtwctlcblockssubsystm.tlc:BlockInstanceData(35)
[02] L:ML_MATLAB64R2021brtwctlclibsyslib.tlc:LibCacheBlockInstanceData(6667)
[03] L:ML_MATLAB64R2021brtwctlcmwformatwide.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? tlc, legacycodetool, sfunction, referencedmodel MATLAB Answers — New Questions