I am trying to use some features from C++ 17, but I am not able to make the compiler working. The compiler does not recognize the directives I use to change the version of C++:
xtensa-lx106-elf-g++: error: unrecognized command line option ‘-std=c++17’
Thank you Max! That seems to be working! However, now I get quite few warnings while compiling. I am not sure why, but they are all inside esp8266 Arduino packages. Why is this happening after using the new toolchain? Or at least how I can easily get rid only of these warnings?
Yet another point, even after adding the line to use the new toolchain, I still see "cppStandard": "c++11" inside c_cpp_properties.json file. Should not this be automatically changed? This makes me confused.
You need to then Ctrl+Click on the time.cpp file in the output and comment out the offending line 27.
After a build, it will then go through with 0 warnings and C++17 actually enabled.
Linking .pio\build\esp01_1m\firmware.elf
Retrieving maximum program size .pio\build\esp01_1m\firmware.elf
Building .pio\build\esp01_1m\firmware.bin
Checking size .pio\build\esp01_1m\firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM: [=== ] 33.6% (used 27536 bytes from 81920 bytes)
Flash: [=== ] 33.9% (used 258576 bytes from 761840 bytes)
Creating BIN file ".pio\build\esp01_1m\firmware.bin" using "C:\Users\Max\.platformio\packages\framework-arduinoespressif8266@src-31d658a59f41540201fc3726a1394910\bootloaders\eboot\eboot.elf" and ".pio\build\esp01_1m\firmware.elf"
==================== [SUCCESS] Took 5.11 seconds ====================
Thanks a lot it works now! I will mark the question as answered. I am just curious to know -if you have any idea- why isn’t C++17 the default at the moment? Is this because this error (the line we need to comment out) in Arduino? Or do you know if this gonna be the default any soon?
I do not like using framework-arduinoespressif8266@https://github.com/esp8266/Arduino.git without specifying a version, because they may break anytime, or what do you think?
The used C++ version is bound to what the people at Arduino-ESP8266 decide to use for the core. And that was last upgraded to Gnu++11 in 2.6.0. PlatformIO must use the same if it wants to stay compatible with how the core is supposed to be compiled (as seen we also get errors if we just try and compile it with C++17) and is compiled in the Arduino IDE. PlatformIO currently uses the latest Arduino-ESP8266 release 2.7.4, which is still at Gnu++11 (Releases · esp8266/Arduino · GitHub). Since the master branch is now at C++17 I’d expect the next release to switch to C++17 and then PIO will pick it up in its normal update cycle.
That’s why we can append a tag / commit hash at the end. See docs (syntax is same). So you can add #20413f817b6456490779a04824cc302e0a5c9779 at the end of the link to fixate the version.