Using S-Function Builder with data type imported from a nested namespace

11 Ansichten (letzte 30 Tage)
PJ
PJ am 24 Nov. 2025
Kommentiert: PJ am 17 Dez. 2025
I want to create an S-Function using data types defined in a header file. The header file contains structs within a namespace. I have imported the data types into a data dictionary via
Simulink.importExternalCTypes('sample.hpp', 'DataDictionary', 'sample_dict', 'Language', 'C++', 'DataDictionarySection','ArchitecturalData');
The dictionary, sample_dict.sldd, contains my data type my_data and includes the following properties:
  • Data scope: Imported
  • Header file: sample.hpp
  • C++ Namespace: foo::bar
I created a Simulink model sample_model, in which I want to create an S-Function with the S-Function Builder block. I populated a bus with dummy data and selected bus: my_data as the data type for the input and output of the S-Function.
If I try to build the S-Function, I get the error "error: 'my_data' does not name a type"... and later "error: 'my_data' was not declared in this scope; did you mean 'foo::bar::my_data'?". I attemped using namespace foo::bar in the #includes section, but that did not fix my issue. Can I use the data type from the namespace in my S-Function interface? If so, how?
The attachment includes the sample header, data dictionary, and model.

Antworten (1)

Aditya
Aditya am 17 Dez. 2025
Hi PJ,
Simulink S-Function Builder can’t find your struct type because it’s defined in a C++ namespace (foo::bar::my_data), but Simulink tries to use just my_data.
Following steps might help you to resolve the issues:
  1. Use the fully qualified name:In S-Function Builder, set the input/output data type to Custom and enter foo::bar::my_data.
  2. Set language to C++:In S-Function Builder settings, select C++ as the language and ensure the source file extension is .cpp.
  3. Include your header:Add #include "sample.hpp" in the S-Function Builder includes.
You can aslo refer to the following documentation for more details :
https://www.mathworks.com/help/simulink/slref/sfunctionbuilder.html
  1 Kommentar
PJ
PJ am 17 Dez. 2025
@Aditya Your recommended Step 1 does not work. The S-Function Builder does not accept the double-colon. It reduces foo::bar::my_data to foobarmy_data. I have performed Steps 2 & 3 but still get errors.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Simulink Coder finden Sie in Help Center und File Exchange

Produkte


Version

R2025a

Community Treasure Hunt

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

Start Hunting!

Translated by