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

25 visualizaciones (últimos 30 días)
PJ
PJ el 24 de Nov. de 2025 a las 20:13
Comentada: PJ el 17 de Dic. de 2025 a las 14:05
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.

Respuestas (1)

Aditya
Aditya el 17 de Dic. de 2025 a las 4:56
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 comentario
PJ
PJ el 17 de Dic. de 2025 a las 14:05
@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.

Iniciar sesión para comentar.

Categorías

Más información sobre Simulink Coder en Help Center y File Exchange.

Productos


Versión

R2025a

Community Treasure Hunt

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

Start Hunting!

Translated by