<string> not supported with platformio with huzzah env?

I’m not sure if this is expected to work or not, but I’ve been attempting to use the STL string. This is the isolated sample I’ve gotten to fail. Can anyone set my expectations or point out what I’m missing?

I setup my directory with platformio init -b huzzah -d . --ide atom. I created this snippet at ./src/test.cpp:

#include <Arduino.h>
#include <string>

void setup()
{
  std::string("something");
}

void loop()
{
}

I compiled with platformio run and get the following output:

[11:42:33] 1 $ platformio run
[Fri Jun 10 11:42:47 2016] Processing huzzah (platform: espressif, board: huzzah, framework: arduino)
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
xtensa-lx106-elf-g++ -o .pioenvs/huzzah/src/test.o -c -fno-rtti -fno-exceptions -std=c++11 -Os -mlongcalls -mtext-section-literals -falign-functions=4 -ffunction-sections -fdata-sections -MMD -DF_CPU=80000000L -D__ets__ -DICACHE_FLASH -DESP8266 -DARDUINO_ARCH_ESP8266 -DARDUINO_ESP8266_ESP12 -DARDUINO=20200 -DPLATFORMIO=020905 -U__STRICT_ANSI__ -I/Users/mg/.platformio/packages/framework-arduinoespressif/tools/sdk/include -I/Users/mg/.platformio/packages/framework-arduinoespressif/tools/sdk/lwip/include -I.pioenvs/huzzah/FrameworkArduino -I.pioenvs/huzzah/FrameworkArduinoVariant -Isrc src/test.cpp
xtensa-lx106-elf-g++ -o .pioenvs/huzzah/firmware.elf -Os -nostdlib -Wl,--no-check-sections -u call_user_start -Wl,-static -Wl,--gc-sections -Wl,-wrap,system_restart_local -Wl,-wrap,register_chipv6_phy -Wl,-T"esp8266.flash.4m1m.ld" .pioenvs/huzzah/src/test.o -L/Users/mg/.platformio/packages/framework-arduinoespressif/tools/sdk/lib -L/Users/mg/.platformio/packages/ldscripts -L.pioenvs/huzzah -Wl,--start-group .pioenvs/huzzah/libFrameworkArduinoVariant.a .pioenvs/huzzah/libFrameworkArduino.a -lmesh -lwpa2 -lsmartconfig -lpp -lmain -lwpa -llwip -lnet80211 -lwps -lcrypto -lphy -lhal -laxtls -lgcc -lm -Wl,--end-group
.pioenvs/huzzah/src/test.o:(.text.setup+0x4): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&)'
.pioenvs/huzzah/src/test.o:(.text.setup+0x8): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
.pioenvs/huzzah/src/test.o: In function `setup':
test.cpp:(.text.setup+0x18): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&)'
test.cpp:(.text.setup+0x20): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
collect2: error: ld returned 1 exit status
scons: *** [.pioenvs/huzzah/firmware.elf] Error 1
======================================================================================= [ ERROR ] Took 1.17 seconds =======================================================================================

Hi @placer14!
Does your example compile well in Arduino IDE?
You can try to add the C++ standard library to your platformio.ini:

[env:huzzah]
platform = espressif
framework = arduino
board = huzzah
build_flags = -lstdc++
1 Like

I do get the same error in ArduinoIDE: gist:fa7fe86402a2e0de701606f2d80081b5 · GitHub
Adding the build flag as you specify produces a different link-time bug: gist:d897b78612f4748b10bb199d2f6a3f85 · GitHub

Hmm, I compiled your example without errors on my Windows machine. What is your OS?

OSX v10.10.5 (14F1713)

PS: I don’t envy you having to support the tool on such a wide-selection of envs, but do appreciate the tool greatly! Thanks for the awesomely prompt responses. (How do you get any development done?!

OK, I reproduced this error in my VM with Ubuntu and looks like this behaviour is fixed in the latest staging framework version. Could you please try to replace the default framework package in /Users/mg/.platformio/packages/framework-arduinoespressif by this one?

PS: Yeah, we just do everything at the same time :slight_smile:

1 Like

It was very happy with the new package.

Does the firmware work as expected after uploading?

I have not tested it on the target with the <string> implementation. I ended up rolling back to use Arduino.h’s String. I will bring it back to <string> later this afternoon and let you know.