Arduino 8266 not working with pio 4.3.1

Sorry colleagues, don’t know what topic my question belongs to, so asking here. Please help. Found that pio uses arduino core and tools with older xtensa toolchain with an old gcc (4.8). It leads to errors like std:regex is not working. Is it possible to update and how? There’s a new toolchain on https://docs.espressif.com/projects/esp-idf/en/release-v3.0/get-started/index.html with gcc 5.2.0 bundled.
I am just a user, have no idea about pio internals. Thought that it is possible. Thank you!

Duplicate of How do I get gcc 5.2.0 compiler in platformIO ESP8266 [SOLVED].

Sorry, as I wrote, I’m not too deep in it yet. Need an advice. I am trying to compile a simple test:

#include <Arduino.h>

#include <string>
#include <regex>

void setup()
{

  Serial.begin(115200);

  delay(1000);

  std::regex rgx("^(.*)\\.(htm|html)$");

  std::smatch matches;

  std::string url = "/index.html";
  bool res = std::regex_search(url, matches, rgx);

  Serial.printf("\n\nsearch=%d, results=%d\n", res, matches.size());

}

void loop()
{
  delay(10000);
}

A advised it that thread, I changed my platformio.ini as follows:

[env:esp12e]
platform = espressif8266
board = esp12e
framework = arduino
upload_speed = 3000000
monitor_speed = 115200
monitor_port = /dev/cu.SLAB*
upload_port = /dev/cu.SLAB*
build_flags = -fexceptions -Teagle.flash.4m1m.ld -std=c++14
build_unflags = -fno-exceptions -std=c++11
platform_packages = toolchain-xtensa @ https://github.com/WallaceWilliam/xtensa-lx106-elf/raw/master/xtensa-lx106-elf-macos-1.22.0-100-ge567ec7-5.2.0.tar.gz

And now it does not link with a lot of undefined reference error, like

Linking .pio/build/esp12e/firmware.elf
.pio/build/esp12e/lib2a7/libESP8266WiFi.a(ESP8266WiFiGeneric.cpp.o): In function `std::_Sp_counted_deleter<WiFiEventHandlerOpaque*, std::__shared_ptr<WiFiEventHandlerOpaque, (__gnu_cxx::_Lock_policy)0>::_Deleter<std::allocator<WiFiEventHandlerOpaque> >, std::allocator<WiFiEventHandlerOpaque>, (__gnu_cxx::_Lock_policy)0>::~_Sp_counted_deleter()':
ESP8266WiFiGeneric.cpp:(.text._ZNSt19_Sp_counted_deleterIP22WiFiEventHandlerOpaqueNSt12__shared_ptrIS0_LN9__gnu_cxx12_Lock_policyE0EE8_DeleterISaIS0_EEES7_LS4_0EED0Ev[std::_Sp_counted_deleter<WiFiEventHandlerOpaque*, std::__shared_ptr<WiFiEventHandlerOpaque, (__gnu_cxx::_Lock_policy)0>::_Deleter<std::allocator<WiFiEventHandlerOpaque> >, std::allocator<WiFiEventHandlerOpaque>, (__gnu_cxx::_Lock_policy)0>::~_Sp_counted_deleter()]+0x7): undefined reference to `operator delete(void*, unsigned int)'
.pio/build/esp12e/lib2a7/libESP8266WiFi.a(ESP8266WiFiGeneric.cpp.o): In function `std::_Function_base::_Base_manager<ESP8266WiFiGenericClass::onStationModeDisconnected(std::function<void (WiFiEventStationModeDisconnected const&)>)::{lambda(_esp_event*)#1}>::_M_manager(std::_Any_data&, std::_Function_base::_Base_manager<ESP8266WiFiGenericClass::onStationModeDisconnected(std::function<void (WiFiEventStationModeDisconnected const&)>)::{lambda(_esp_event*)#1}> const&, std::_Manager_operation)':
ESP8266WiFiGeneric.cpp:(.text._ZNSt14_Function_base13_Base_managerIZN23ESP8266WiFiGenericClass25onStationModeDisconnectedESt8functionIFvRK32WiFiEventStationModeDisconnectedEEEUlP10_esp_eventE_E10_M_managerERSt9_Any_dataRKSC_St18_Manager_operation+0x3e): undefined reference to `operator delete(void*, unsigned int)'
ESP8266WiFiGeneric.cpp:(.text._ZNSt14_Function_base13_Base_managerIZN23ESP8266WiFiGenericClass25onStationModeDisconnectedESt8functionIFvRK32WiFiEventStationModeDisconnectedEEEUlP10_esp_eventE_E10_M_managerERSt9_Any_dataRKSC_St18_Manager_operation+0x5c): undefined reference to `operator delete(void*, unsigned int)'

And so on.
I also didn’t understand what is discussed in that thread regarding xtensa toolchain, since the last one I just downloaded has 5.2.0, not 4.8. I just have no idea how it works inside pio and how to replace it.

Please help.

Hm seems like it has a secondary error when compiling the Arduino Framework, specifically the ESP82566WiFiGenericClass stuff. I’ll look into.

You can get the example to compile but not work properly with the following platformio.ini:

build_flags =  -fexceptions  -Teagle.flash.4m1m.ld -std=gnu++14 -D_GLIBCXX_USE_CXX11_ABI=0
build_unflags = -fno-exceptions -std=c++11

and add to the code

#include <Arduino.h>

#include <string>
#include <regex>


void operator delete(void * ptr, size_t size){
 free(ptr);
}

void operator delete[](void * ptr, size_t size){
 free(ptr);
}

void setup()
{

  Serial.begin(115200);
  Serial.println("Hello world!");
  Serial.flush();

  delay(1000);

  static std::regex rgx("^(.*)\\.(htm|html)");

  static std::smatch matches;

  static std::string url = "/index.html";

  Serial.println("Before regex_search()");
  Serial.flush();
  delay(1000);

  bool res = std::regex_search(url, matches, rgx);

  Serial.printf("\n\nmatch = %d search=%d, results=%d\n", res? 1: 0, res, matches.size());
}

void loop()
{
  delay(10000);
}

It then uses GCC 5.2.0 but std::regex is still broken, output is

match = 0 search=0, results=0

However there is a pull-request which modifies some code to get std::regex working. This uses GCC 9.

I’ll try and integrate that.

@bbiktop can you verify that std::regex also does not work in the Arduino IDE with the latest official version?

Yeah that special framework version and GCC9 are working perfectly.

Can you try the following platformio.ini:

[env:esp12e]
platform = espressif8266
board = esp12e
framework = arduino
upload_speed = 3000000
monitor_speed = 115200
monitor_port = /dev/cu.SLAB*
upload_port = /dev/cu.SLAB*
build_flags =  -fexceptions  -Teagle.flash.4m1m.ld -std=c++14 
build_unflags = -fno-exceptions -std=c++11
platform_packages = 
	framework-arduinoespressif8266 @ https://github.com/earlephilhower/Arduino.git#gcc9.1
	toolchain-xtensa @ https://github.com/maxgerhardt/xtensa-lx106-elf/raw/master/xtensa-lx106-elf-darwin64-9-2-0.zip

(already adapted for Darwin x64 targets)

with the code

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

void setup()
{

  Serial.begin(115200);
  Serial.println("Hello world!");
  Serial.flush();

  delay(1000);

  std::regex rgx("^(.*)\\.(htm|html)");

  std::smatch matches;

  std::string url = "/index.html";

  Serial.println("Before regex_search()");
  Serial.flush();
  delay(1000);

  bool res = std::regex_search(url, matches, rgx);

  Serial.printf("\n\nmatch = %d search=%d, results=%d\n", res? 1: 0, res, matches.size());
}

void loop()
{
  delay(10000);
}

should produce

match = 1 search=1, results=3<\n>
Hello world!
Before regex_search()


match = 1 search=1, results=3

Sure I did. The same result as it uses the same version.

Hm, it may be that I only have Windows at hand right now and the archive for Mac uses permissions of the zip archive which are wrongly set when created with Windows.

Please do:

{
    "description": "xtensa-gcc",
    "name": "toolchain-xtensa",
    "system": [
        "darwin_x86_64"
    ],
    "url": "https://github.com/earlephilhower/esp-quick-toolchain",
    "version": "9.2.0"
}
  • make sure the file structure in the folder is like

  • create an archive (.zip or .tar.gz) that includes all these files (no intermediate folder)
  • upload it to github in a repo or any other place which has a direct download link
  • use the raw download link in the toolchain-xtensa @ ... url in the platformio.ini.

Tried to set permissions but it downloads it again and overwrites. Is it supposed to be so? Also made touch - still downloads. Will place it locally as you suggested and let you know, thank you

Do I need to remain this url unchanged?

The URL doesn’t need to be changed as it’s just informative description, it’s not used.

Yes, in this case it is working, thank you very much. How safe is it to use this in the production?

Yay :grinning:

Well the Arduino-Framework modifications for GCC9 is from a not-yet-merged but developer-approved pull request of some external developer and the GCC9 compiler toolchain is provided by the same guy, but Arduino-ESP8266 also directly points at his repository for the toolchain. I have no accounts or experience regarding the stability of that branch since I’ve only first seen it today, too.

If you want to use this professionally (with Arduino in general that’s always an interesting question…) you should at least make sure to only use github repositories that you control. E.g., in my platformio.ini example, I directly link to https://github.com/earlephilhower/Arduino.git#gcc9.1. And of course, verify the firmware as best as you can.

If you want to use the current Arduino core and the compiler they use, then you have to find an alternative library to std::regex or a different approach without RegExes.

It’s not me, it’s a library that uses it. Of course, by “production” I mean some home use, not a medical or nuclear reactor control. Well, thank you very much for your help! I suppose I’d really rather use another library, there’s a large set of that to choose. And will modify the library then, as it’s opensource