Why do I get "identifier is undefined" and "expected an expression" errors when using the Simulink Code Importer tool?

I am trying to import code using the Simulink Code Importer tool, or its graphical wizard, documented here:

https://www.mathworks.com/help/releases/R2023a/simulink/code-importer.html

https://www.mathworks.com/help/releases/R2023a/simulink/ug/import-custom-code-using-the-simulink-code-importer-wizard.html

When doing so, I get errors that look like the following:

Failed to parse custom code.
Caused by:
"/path/to/my_header.h", line L: error: identifier "namespace" is undefined
| namespace my_ns {
| ^
"/path/to/my_header.h", line L: error: expected a ";"
| namespace my_ns {
| ^
"/path/to/my_impl", line M: error: identifier "using" is undefined
| using foo = my_template<baz>;
| ^
"/path/to/my_impl", line M: error: identifier "my_template" is undefined
| using foo = my_template<baz>;
| ^
"/path/to/my_impl", line M: error: expected an expression
| using foo = my_template<baz>;
| ^
"/path/to/my_impl", line N: error: expected a ";"
| template
Why is this happening? I know the code is valid, I can compile it manually without any issues.

 Accepted Answer

The code shown in these errors indicates that the custom code you are providing was written in C++, but the default option for the Code Importer tool is to parse files as C code. When providing your source and header files to the Code Importer, you also need to change the language to C++.
If you are using the command-line interface, set the "CustomCode.Language" property of your "CodeImporter" object to "C++". If you are using the graphical wizard, once you get to the "Specify Custom Code" step, change the "Language" option to "C++".

More Answers (0)

Categories

Find more on Embedded Coder in Help Center and File Exchange

Products

Release

R2023a

Community Treasure Hunt

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

Start Hunting!