I would like to see a more recent version of GCC used so that I can make it work correctly with a new library I'm working on that uses at least C++14 features.
Notably, the Arduino distribution AVR compiler does support C++14.
But hey, if you're going to update the compiler, you may as well go all the way to c++17 since the ABI changes are probably not too big an issue (I don't know, just suspecting).
Can you be more specific about what support you need?
ESP-IDF uses xtensa-esp32-elf-gcc version 5.2.0, which AFAIK supports all of C++14.
ESP-IDF build system defaults to building C++ source with -std=gnu++11, but for your own components you can modify this in component.mk, ie:
CFLAGS += -std=c++14
(Docs)
Or if you using CMake, modify CMakeLists.txt with
component_compile_options(-std=c++14)
(Docs).
you may as well go all the way to c++17
We plan to switch to GCC 8 (which supports all of C++17) for IDF V4.0.
GCC 8 support may be available as an option in v3.x as well, depending on how testing goes.
GCC 8 support may be available as an option in v3.x as well, depending on how testing goes.
This happened sooner than I expected! https://esp32.com/viewtopic.php?f=10&t=7400
So when will toolchan be released from beta? Is it still WIP?
@igrr Hi, any updates? Thanks.
Still WIP, but we plan to release an update to GCC 8 based toolchain soon, and switch to GCC 8 as the default toolchain in IDF v4.0.
New preview release of the toolchain with GCC 8.2 is now available, see https://www.esp32.com/viewtopic.php?f=10&t=7400&p=31257#p41667.
Nice please make sure LTO and objcopy is working, there were some problems in the original arm-gcc 8.2 release: https://gnu-mcu-eclipse.github.io/blog/2019/02/14/arm-none-eabi-gcc-v8-2-1-1-4-released/#changes
how to enable c++ 17 ? i tried adding
COMPONENT_COMPILE_OPTIONS := -std=c++17
to my component.mk but it doesn't seem to work
Ideally there would be a CONFIG_CXX_STANDARD in the sdkconfig but that doesn't exist yet. Instead I just manually edited esp-idf/make/project.mk (or esp-idf/tools/cmake/idf_functions.cmake for CMake) and changed gnu++11 to gnu++17. Worked perfectly as far as I can tell.
@Timmmm Why do you want to compile IDF itself in C++17 mode? You can set it using CMake commands for your project/component target I think. As for old build, I was using c++14 before by setting CXX flags without any problems, shouldn't be different for C++17.
Also usage of global (non-target) variables like CONFIG_CXX_STANDARD is really deprecated in modern CMake and should be avoided.
Is std::filesystem supposed to be available with this gcc 8?
Using my system default compiler (gcc (Ubuntu 8.3.0-6ubuntu1) 8.3.0) and target_link_libraries(${PROJECT_NAME} stdc++fs) everything compiles.
Using xtensa-esp32-elf-gcc (crosstool-NG esp32-2019r1-rc2) 8.2.0 I get
xtensa-esp32-elf/bin/ld: cannot find -lstdc++fs
@Timmmm Why do you want to compile IDF itself in C++17 mode?
I don't. The -std=gnu++11 flag is added in IDF for all source files. See the files that I mentioned.
Also usage of global (non-target) variables like
CONFIG_CXX_STANDARDis really deprecated in modern CMake and should be avoided.
I wasn't talking about CMake.
@Timmmm I use this for C++14 (in component.mk):
CXXFLAGS += -std=gnu++14
Try something like this for C++17?
@v1993 That didn't work when I tried it for some reason, and won't that give you both flags in the command line?
Also, it won't matter in practice in this case but it's worth pointing out that linking different versions of C++ is technically not allowed, so you really should compile everything as C++17.
@Timmmm It worth pointing out that it is safe in GCC: https://stackoverflow.com/q/46746878/5697743
@PerMalmberg At the moment, std::filesystem code is not available. It depends on several functions which aren't provided in our newlib builds (ref GLIBCXX_CHECK_FILESYSTEM_DEPS in libstdc++ source). It will likely be a larger task to provide some stubs for all the filesystem functions...
@igrr Ok, thanks for the quick reply.
Perhaps make a note of what major things that are not included in the post of the forum?
Most helpful comment
This happened sooner than I expected! https://esp32.com/viewtopic.php?f=10&t=7400