如何在 PlatformIO 中使用 ESP32 / Arduino 的 C++17 / C++23
问题:
默认情况下,PlatformIO 使用 -std=gnu++11 作为编译器标志,但你想使用 C++17 或 C++23 功能。
如果你只使用
platformio.ini
build_flags = -std=gnu++17这将导致 g++ 被调用时带有 g++ ... -std=gnu++17 ... -std=gnu++11 ... 编译器标志。后者 - gnu++11 即 C++11 将优先。
解决方案
要激活 C++17,使用
platformio.ini
build_flags = -std=gnu++17
build_unflags = -std=gnu++11要激活 C++23(G++ 中尚未完全实现),你目前需要使用 -std=gnu++2a:
platformio.ini
build_flags = -std=gnu++2a
build_unflags = -std=gnu++11Check out similar posts by category:
Arduino, ESP8266/ESP32, PlatformIO
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow