Which C++ standard am I using?

I’m having a hard time determining which C++ standard I am using when building for ESP32 and which C++ features are available.

When I run in verbose mode, I see that I am using the package:

  • toolchain-xtensa32 2.50200.97 (5.2.0)
    Is this what dictates the C++ compiler and standard utilized?

I know this is a very basic question, but I’ve spent many hours googling and somehow still haven’t figured out the answer. Ultimately, I have read about C++20 and the introduction of “modules”. I would like to implement this feature, but from my reading, it seems like platformIO does not yet implement the C++20 standard? I do see C++ standards referenced when the IDE highlights my errors (e.g. identifier “import” is undefined C/C++(20)). But am I right to assume that the error checking standard is separate from the actual compilation standard?

That only says that XTensa GCC / G++ version 5.2.0 is used, not the C++ version. You can always use the project tasks “Clean” followed by “Advanced → Verbose Build” to inspect all exact compiler invocations. Among it, it will have a -std=x switch with x being the language standard – no guesswork needed.

1 Like

Thanks for the help.
I was running pio run -v from the command line and thought this would give me verbose build information. After running “Advanced → Verbose Build”, I see a lot more verbosity.

In the verbose logging, I see a reference to -std=gnu++11. I also see many (19) references to -std=gnu99. Does this mean that I am using C++11 as my C++ standard and C99 as my C standard? And do the multiple references result from each package declaring its own compiler options?

I am surprised at the use of such an old standard. I see that I can request newer standards with build flags.

But it also looks like this can cause errors and would definitely need an updated toolchain (link, link, link). I’m guessing this is just something a beginner should avoid?

PlatformIO follows the compilation settings of the original frameworks, so e.g. for ESP32 + Arduino (core 1.0.6), C++11 is the standard used in there in the Arduino IDE, and so PlatformIO has that as a default. If the used compiler is capable of a higher C++ standard and if the code is compilable for that higher standard, build_unflags and build_flags can be used.

If we’re talking about the standard ESP32 + Arduino case here, note that PlatformIO is currently lagging behind regarding the used core version, and with it the used C++ standard (see issue).

As can be deducted from this comment, it’s possible to get a technical preview of the 2.0.1 core with C++2a (highest version in the 8.4.0 compiler) by using the platformio.ini

[env:esp32dev]
platform = https://github.com/platformio/platform-espressif32.git#feature/arduino-idf-master
board = esp32dev
framework = arduino
platform_packages =
   framework-arduinoespressif32 @ https://github.com/espressif/arduino-esp32.git#2.0.1
build_unflags = -std=gnu++11
build_flags = -std=gnu++2a

NOTE: The information in this post is outdated and the platformio.ini should not be used anymore. While the Arduino-ESP32 core still uses Gnu++11

https://github.com/espressif/arduino-esp32/blob/master/tools/platformio-build-esp32.py#L50-L55

the custom platform and platform_packages should not be used anymore. Instead just:

[env:esp32dev]
platform = espressif32
board = esp32dev
framework = arduino
build_unflags = -std=gnu++11
build_flags = -std=gnu++2a
3 Likes