How to use modern features (notably std::unique_ptr) in the C++ code of my S-functions while using the linaro v4.8 toolchain in embedded coder?

7 次查看(过去 30 天)
Background
I am using simulink with S-functions containing custom C++ code. My simulink model runs on an ARM board running Linux, using embedded coder. My C++ code uses unique pointers (std::unique_ptr). The toolchain I use is Linaro v4.8.
The error
I get the following error when building the Linux executable using the simulink 'build' button:
C:/my_path/cpp/src/my_class.h:13:5: error: 'unique_ptr' in namespace 'std' does not name a type
My idea
I suspect that the C++ version being compiled to is < c++11, and I would like to force the g++ compiler to compile the code using c++11. I can't change compiler flags in the simulink menu, it is grayed out.
I found the linaro toolchain xml file and changed compiler flags there, but when I look at the compiler command generated in simulink I do not see the -std=c++11 compiler flag anywhere.
The question
How can I use modern features (notably std::unique_ptr) in the C++ code of my S-functions while using the linaro v4.8 toolchain in simulink embedded coder?

回答(1 个)

Satwik
Satwik 2024-8-2
Hi,
I understand you are facing the following error while building the Linux executable using the Simulink 'build' button:
C:/my_path/cpp/src/my_class.h:13:5: error: 'unique_ptr' in namespace 'std' does not name a type
A possible reason for this error is the absence of required header files for ‘std::unique_ptr’. Please ensure you have included the ‘<memory>’ header file by adding the following line at the beginning of your custom C++ code:
‘#include <memory>’.
Now, based on your idea, assuming that you have included the required header files, the error might be occurring due to the C++ version being used. According to the following documentation, the default version used is C++11 (ISO):
The above documentation also covers the steps you need to follow to enforce the compiler to compile in a specific version of C++. The steps are as follows:
  1. In the Configuration Parameters dialog box, set ‘Build configuration’ to ‘Specify’.
  2. Under Toolchain details, at the end of the C Compiler and C++ Compiler Options field entries, manually add these compiler flags: When the Language standard is set to C++11, add the flag ‘-std=c++11 -pedantic’.
Another possible cause of the error you are facing might be incorrect configuration of the toolchain. You can refer to this documentation to correctly specify the toolchain in the ‘Configuration Parameters’: https://www.mathworks.com/help/rtw/ug/program-builds.html
For more information on how to troubleshoot compiler issues, you may refer to the documentation given below:
I hope this helps!

类别

Help CenterFile Exchange 中查找有关 Deployment, Integration, and Supported Hardware 的更多信息

产品


版本

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by