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

조회 수: 29 (최근 30일)
PJ
PJ 2025년 11월 24일 20:13
댓글: PJ 2025년 12월 17일 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.

답변 (1개)

Aditya
Aditya 2025년 12월 17일 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
PJ
PJ 2025년 12월 17일 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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Simulink Coder에 대해 자세히 알아보기

제품


릴리스

R2025a

Community Treasure Hunt

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

Start Hunting!

Translated by