ESP32 with C++ 20 for std::span

I´d like to use std::span with ESP32s.

Found some posts here how it is done, and also one with ESP8266 using std::span.
I followed the instructions in the posts, but it seems I am missing something.

I updated gcc

gcc.exe (MinGW-W64 x86_64-ucrt-mcf-seh, built by Brecht Sanders) 13.2.0

Also platform toolchain is latest

PLATFORM: Espressif 32 (6.3.2+sha.f1fdbc5) > WEMOS LOLIN32

Which, if I understand correct, also updates the packages

  • framework-arduinoespressif32 @ 3.20011.230801 (2.0.11)
  • tool-esptoolpy @ 1.40501.0 (4.5.1)
  • toolchain-xtensa-esp32 @ 8.4.0+2021r2-patch5

For testing I created a new project. No code was written, I only
#include <span>
in the main.cpp

platformio.ini reads

platform = espressif32
board = lolin32
framework = arduino

build_unflags =

build_flags =

Unflags were collected from various posts.

When building, I get the error

src/main.cpp:3:10: fatal error: span: No such file or directory

std::span is definitely part of C++20. Also the post mentioned at the top refers to it running fine with ESP8266.

So what could I be missing?

Wut? Updating your local GCC installation that’s compiling for x86_64, aka your Desktop, has 0 effect on which toolchain PlatformIO uses for the XTensa32 architecture. PlatformIO strictly decouples the used build toolchain from whatever is regularly installed on your computer. The first thing that would be in order is to upgrade the actual toolchain package: PlatformIO Registry

Per documentation.

platform_packages =

You might then also need just -std=gnu++20 instead of 2a.

1 Like

Oh, okay, wasn´t aware of that fact :sweat_smile:

Now it builds (strangely no matter if gnu++20 or gnu++2a) , thank you very much!

But now I also get a lot of warnings (multiple pages), f.e.

C:/Users/Inso/.platformio/packages/framework-arduinoespressif32/tools/sdk/esp32/include/freertos/port/xtensa/include/freertos/portmacro.h:614:1: warning: ignoring attribute ‘section (“.iram1.24”)’ because it conflicts with previous ‘section (“.iram1.22”)’ [-Wattributes]

just want to be sure that this is normal^^.

Well as you can see in, the current latest core version 2.0.11 is declaring its tool dependency as

              "packager": "esp32",
              "name": "xtensa-esp32-elf-gcc",
              "version": "esp-2021r2-patch5-8.4.0"

So the core is in theory unprepared to be compiled under any other toolchain version or C++ language version. Use at your own risk.

The higher 12x toolchain may however be used in ESP-IDF which is why Espressif uploaded it.