- In the Configuration Parameters dialog box, set ‘Build configuration’ to ‘Specify’.
- 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’.
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?
0 件のコメント
回答 (1 件)
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:
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!
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Deployment, Integration, and Supported Hardware についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!