- Add libstdcpp feature to indicate a platform is providing a libstdc++ implementation ready for use - The existing cpp feature now only indicates a working C++ toolchain without libstdc++. (E.g. still useful for the Arduino compatibility layer.) - Added libstdcpp as required feature were needed - Added some documentation on C++ on RIOT
2.0 KiB
2.0 KiB
Using C++ in RIOT
[TOC]
Levels of Support
A CPU in RIOT can have three levels of support for C++ code:
- No support for C++ at all
- C++ is supported, but no libstdc++ implementation is available
- C++ is supported and a libstdc++ implementation is available
The reason for missing or only partial C++ support can be one (or more) of the following:
- No libstdc++ implementation for the target platform is available to RIOT, or the official RIOT docker image is missing it
- Missing toolchain support for a given target platform
- The C++ toolchain requires library code (such as constructor guards for the thread safe initialization of statically allocated instances) or hooks in the startup process to perform initialization
Using C++
In order for C++ code to compile with RIOT, the following needs to be done:
- All C++ files must have the file extension
.cpp, all C++ headers.hpp- For external code, overwriting the make variable
SRCXXEXTe.g. tocxxcan be used to compile C++ files with other extensions, e.g..cxx
- For external code, overwriting the make variable
FEATURES_REQUIRED += cppmust be added to the applicationsMakefile- If additionally the libstdc++ is used,
FEATURES_REQUIRED += libstdcppmust be used additionally
- If additionally the libstdc++ is used,
RIOT Modules in C++
RIOT modules should be written in C, so that boards/platforms without or partial
C++ support can still use these modules. However, external modules, packages,
and modules that require C++ support anyway (e.g. the Arduino compatibility
features) can be written in C++. These modules/packages have to depend on the
cpp feature (FEATURES_REQUIRED += cpp) and possibly the libstdcpp
feature using their Makefile.dep.
See Also
@ref sys_c11_atomics_cpp_compat, @ref cpp11-compat