esp-idf: Missing std::to_string C++ support (libstdc++) (IDFGH-133)
I notice that std::to_string support is missing from the libstdc++, not sure what it takes to get that added, but it is useful especially when porting other C++11 code.
Specifically, the following app_main should work. The example usage is directly from cppreference:
http://www.cplusplus.com/reference/string/to_string/
(it currently fails to compile)
// to_string example
#include <iostream> // std::cout
#include <string> // std::string, std::to_string
#ifdef __cplusplus
extern "C"
#endif // __cplusplus
void app_main()
{
std::string pi = "pi is " + std::to_string(3.1415926);
std::string perfect = std::to_string(1+2+4+7+14) + " is a perfect number";
std::cout << pi << '\n';
std::cout << perfect << '\n';
}
The error I see when running make:
./hello_world_main.cpp: In function 'void app_main()':
./hello_world_main.cpp:10:31: error: 'to_string' is not a member of 'std'
std::string pi = "pi is " + std::to_string(3.1415926);
^
./hello_world_main.cpp:11:25: error: 'to_string' is not a member of 'std'
std::string perfect = std::to_string(1+2+4+7+14) + " is a perfect number";
^
make[1]: *** [hello_world_main.o] Error 1
make: *** [component-main-build] Error 2
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 15 (11 by maintainers)
Commits related to this issue
- Working on ESP8266 build with PlatformIO and the ESP8266 RTOS SDK. Not usable yet. Problem: the library json.hpp uses std::to_string, which is not available in the current STL implementation of the x... — committed to danielschenk/PianoLeds2 by danielschenk 6 years ago
- update toolchain to esp32-2019r1 release Closes https://github.com/espressif/esp-idf/issues/1445 (std::to_string) Closes https://github.com/espressif/esp-idf/issues/1876 (std::chrono_steady_clock) Cl... — committed to trombik/esp-idf by igrr 5 years ago
- [OTA] Add UserSelectable timeout for invitation to device + check for OK result in the last few messages (#1445) — committed to 0xFEEDC0DE64/esp-idf by tsathishkumar 6 years ago
I’ve been wanting to use
std::to_string()too. Today I took the time to dig into the source and found that adding this to yourcomponent.mkallows usage ofstd::to_string(),CPPFLAGS += -D_GLIBCXX_USE_C99I don’t know if there are any side effects, seems to work fine though.
Half a year later - how is the time schedule looking for switching to a new gcc @igrr ?
Fixed in https://github.com/espressif/esp-idf/commit/9240bbb708453251ddacc4d1c5a7e9a83c999da1, sorry that I forgot to tag this issue.
@PerMalmberg There is a preview version of toolchain based on GCC 8.2 available now, please see https://esp32.com/viewtopic.php?f=10&t=7400.
Will keep this issue open while the new version is in preview.
@PerMalmberg I can confirm that seems to work for me. I’m applying it selectively to the files that need it (i.e. are using
std::to_string).I’m also curious about any potential downsides? And/or if we will be getting a significantly new toolchain version any time soon?
Some libstdc++ features which depend on C99 support in C library are currently unavailable, because GCC 5.2.0 incorrectly checks for these C99 features during configuration step. We plan to switch to a more recent version of GCC in the future, which will also fix this configuration issue.