Linking error using Arduino library with c++'s stringstream

1.1k views Asked by At

I am using an esp8266 together with platformio to write a simple sketch.

#include <sstream>
#include <Arduino.h>

std::stringstream s;

void setup()
{
    Serial.begin(9600);
    Serial.println("Test");
}

void loop()
{

}

Everything should be setup correctly and most sketches worked without issues. But as soon as I try to use stringstreams I get errors when platformio is linking the firmware.

platformio run
[12/29/16 12:11:32] Processing esp12e (platform: espressif8266, board: nodemcu, framework: arduino)

Verbose mode can be enabled via `-v, --verbose` option
Collected 23 compatible libraries
Looking for dependencies...
Project does not have dependencies
Linking .pioenvs\esp12e\firmware.elf

c:/users/simon/.platformio/packages/toolchain-xtensa/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld.exe: .pioenvs\esp12e\firmware.elf section `.text' will not fit in region `iram1_0_seg'
C:\users\simon\.platformio\packages\framework-arduinoespressif8266\tools\sdk\lib\libstdc++.a(locale-inst.o):(.literal._ZSt16__convert_from_vRKPiPciPKcz[_ZSt16__convert_from_vRKPiPciPKcz]+0x4): undefined reference to `setlo
cale'
C:\users\simon\.platformio\packages\framework-arduinoespressif8266\tools\sdk\lib\libstdc++.a(locale-inst.o):(.literal._ZSt16__convert_from_vRKPiPciPKcz[_ZSt16__convert_from_vRKPiPciPKcz]+0xc): undefined reference to `vspri
ntf'
C:\users\simon\.platformio\packages\framework-arduinoespressif8266\tools\sdk\lib\libstdc++.a(locale-inst.o):(.literal._ZSt9use_facetISt5ctypeIcEERKT_RKSt6locale[_ZSt9use_facetISt5ctypeIcEERKT_RKSt6locale]+0x4): undefined r
eference to `std::__throw_bad_cast()'
C:\users\simon\.platformio\packages\framework-arduinoespressif8266\tools\sdk\lib\libstdc++.a(locale-inst.o):(.literal._ZNKSt7num_putIcSt19ostreambuf_iteratorIcSt11char_traitsIcEEE15_M_insert_floatIdEES3_S3_RSt8ios_baseccT_
[_ZNKSt7num_putIcSt19ostreambuf_iteratorIcSt11char_traitsIcEEE15_M_insert_floatIdEES3_S3_RSt8ios_baseccT_]+0x0): undefined reference to `memchr'
C:\users\simon\.platformio\packages\framework-arduinoespressif8266\tools\sdk\lib\libstdc++.a(locale-inst.o): In function `std::__convert_from_v(int* const&, char*, int, char const*, ...)':
/Users/igrokhotkov/e/ESPTools/crosstool-NG/.build/xtensa-lx106-elf/build/build-cc-gcc-final/xtensa-lx106-elf/libstdc++-v3/include/bits/locale_classes.tcc:114: undefined reference to `setlocale'
/Users/igrokhotkov/e/ESPTools/crosstool-NG/.build/xtensa-lx106-elf/build/build-cc-gcc-final/xtensa-lx106-elf/libstdc++-v3/include/bits/locale_classes.tcc:114: undefined reference to `setlocale'
/Users/igrokhotkov/e/ESPTools/crosstool-NG/.build/xtensa-lx106-elf/build/build-cc-gcc-final/xtensa-lx106-elf/libstdc++-v3/include/bits/locale_classes.tcc:114: undefined reference to `vsprintf'
/Users/igrokhotkov/e/ESPTools/crosstool-NG/.build/xtensa-lx106-elf/build/build-cc-gcc-final/xtensa-lx106-elf/libstdc++-v3/include/bits/locale_classes.tcc:114: undefined reference to `setlocale'
C:\users\simon\.platformio\packages\framework-arduinoespressif8266\tools\sdk\lib\libstdc++.a(locale-inst.o): In function `std::ctype<char> const& std::use_facet<std::ctype<char> >(std::locale const&)':
/Users/igrokhotkov/e/ESPTools/crosstool-NG/.build/xtensa-lx106-elf/build/build-cc-gcc-final/xtensa-lx106-elf/libstdc++-v3/include/bits/locale_classes.tcc:114: undefined reference to `std::__throw_bad_cast()'
C:\users\simon\.platformio\packages\framework-arduinoespressif8266\tools\sdk\lib\libstdc++.a(locale-inst.o): In function `std::numpunct<char> const& std::use_facet<std::numpunct<char> >(std::locale const&)':
/Users/igrokhotkov/e/ESPTools/crosstool-NG/.build/xtensa-lx106-elf/build/build-cc-gcc-final/xtensa-lx106-elf/libstdc++-v3/include/bits/locale_classes.tcc:114: undefined reference to `std::__throw_bad_cast()'
C:\users\simon\.platformio\packages\framework-arduinoespressif8266\tools\sdk\lib\libstdc++.a(locale-inst.o): In function `std::num_put<char, std::ostreambuf_iterator<char, std::char_traits<char> > > const& std::use_facet<s
td::num_put<char, std::ostreambuf_iterator<char, std::char_traits<char> > > >(std::locale const&)':
/Users/igrokhotkov/e/ESPTools/crosstool-NG/.build/xtensa-lx106-elf/build/build-cc-gcc-final/xtensa-lx106-elf/libstdc++-v3/include/bits/locale_classes.tcc:114: undefined reference to `std::__throw_bad_cast()'
C:\users\simon\.platformio\packages\framework-arduinoespressif8266\tools\sdk\lib\libstdc++.a(locale-inst.o): In function `std::num_get<char, std::istreambuf_iterator<char, std::char_traits<char> > > const& std::use_facet<s
td::num_get<char, std::istreambuf_iterator<char, std::char_traits<char> > > >(std::locale const&)':
/Users/igrokhotkov/e/ESPTools/crosstool-NG/.build/xtensa-lx106-elf/build/build-cc-gcc-final/xtensa-lx106-elf/libstdc++-v3/include/bits/locale_classes.tcc:114: undefined reference to `std::__throw_bad_cast()'
C:\users\simon\.platformio\packages\framework-arduinoespressif8266\tools\sdk\lib\libstdc++.a(locale-inst.o): In function `std::moneypunct<char, true> const& std::use_facet<std::moneypunct<char, true> >(std::locale const&)'
:
/Users/igrokhotkov/e/ESPTools/crosstool-NG/.build/xtensa-lx106-elf/build/build-cc-gcc-final/xtensa-lx106-elf/libstdc++-v3/include/bits/locale_classes.tcc:114: undefined reference to `std::__throw_bad_cast()'
C:\users\simon\.platformio\packages\framework-arduinoespressif8266\tools\sdk\lib\libstdc++.a(locale-inst.o):/Users/igrokhotkov/e/ESPTools/crosstool-NG/.build/xtensa-lx106-elf/build/build-cc-gcc-final/xtensa-lx106-elf/libst
dc++-v3/include/bits/locale_classes.tcc:114: more undefined references to `std::__throw_bad_cast()' follow
C:\users\simon\.platformio\packages\framework-arduinoespressif8266\tools\sdk\lib\libstdc++.a(locale-inst.o): In function `std::ostreambuf_iterator<char, std::char_traits<char> > std::num_put<char, std::ostreambuf_iterator<
char, std::char_traits<char> > >::_M_insert_float<double>(std::ostreambuf_iterator<char, std::char_traits<char> >, std::ios_base&, char, char, double) const':
/Users/igrokhotkov/e/ESPTools/crosstool-NG/.build/xtensa-lx106-elf/build/build-cc-gcc-final/xtensa-lx106-elf/libstdc++-v3/include/bits/locale_classes.tcc:114: undefined reference to `memchr'
C:\users\simon\.platformio\packages\framework-arduinoespressif8266\tools\sdk\lib\libstdc++.a(locale-inst.o): In function `std::ostreambuf_iterator<char, std::char_traits<char> > std::num_put

A lot more similar errors

----------

collect2.exe: error: ld returned 1 exit status
*** [.pioenvs\esp12e\firmware.elf] Error 1
 [ERROR] Took 8.38 seconds

I am quite new to platformio and programming the esp but maybe some of you encountered a similar issue or got clues from the console log. Could you help me fix these errors?

1

There are 1 answers

0
Patrick Trentin On

As far as I know, you cannot easily include sstream in your project nor most other C++ libraries.

Arduino has his own libraries, I advice you to take a closer look to the String documentation as it might already provide the functionality you need in your project.

There are some C++ library ports out there for Arduino, including a StringStream port that --theoretically speaking-- you could use.

There are also ports of C libraries, but I honestly don't know what is the state of advancement/reliability of these libraries.