- Use the fully qualified name:In S-Function Builder, set the input/output data type to Custom and enter foo::bar::my_data.
- Set language to C++:In S-Function Builder settings, select C++ as the language and ensure the source file extension is .cpp.
- Include your header:Add #include "sample.hpp" in the S-Function Builder includes.
Using S-Function Builder with data type imported from a nested namespace
11 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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.
0 Kommentare
Antworten (1)
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:
You can aslo refer to the following documentation for more details :
https://www.mathworks.com/help/simulink/slref/sfunctionbuilder.html
Siehe auch
Kategorien
Mehr zu Simulink Coder finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!