ESP8266: Upload fails - xtensa-lx106-elf-g++: not found

I am trying to flash a script to a ESP8266 which is connected to a Raspberry Pi 4B but it is not working. This is the output I get:

Processing esp8266 (platform: espressif8266; board: esp12e; framework: arduino)
----------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/espressif8266/esp12e.html
PLATFORM: Espressif 8266 (4.2.0) > Espressif ESP8266 ESP-12E
HARDWARE: ESP8266 80MHz, 80KB RAM, 4MB Flash
PACKAGES:
 - framework-arduinoespressif8266 @ 3.30102.0 (3.1.2)
 - tool-esptool @ 1.413.0 (4.13)
 - tool-esptoolpy @ 1.30000.201119 (3.0.0)
 - tool-mklittlefs @ 1.203.210628 (2.3)
 - tool-mkspiffs @ 1.200.0 (2.0)
 - toolchain-xtensa @ 2.100300.220621 (10.3.0)
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 53 compatible libraries
Scanning dependencies...
Dependency Graph
|-- NTPClient @ 3.2.1
|-- RemoteDebug @ 2.1.2
|   |-- ESP8266WiFi @ 1.0
|-- PubSubClient @ 2.8.0
|-- Sensirion I2C SCD4x @ 0.3.1
|   |-- Wire @ 1.0
|   |-- Sensirion Core @ 0.6.0
|   |   |-- Wire @ 1.0
|-- Adafruit SHT31 Library @ 2.2.0
|   |-- Adafruit BusIO @ 1.14.1
|   |   |-- Wire @ 1.0
|   |   |-- SPI @ 1.0
|   |-- Wire @ 1.0
|-- Adafruit TSL2561 @ 1.1.0
|   |-- Adafruit Unified Sensor @ 1.1.9
|   |-- Wire @ 1.0
|-- Adafruit AS7341 @ 1.3.3
|   |-- Adafruit BusIO @ 1.14.1
|   |   |-- Wire @ 1.0
|   |   |-- SPI @ 1.0
|   |-- Wire @ 1.0
|   |-- SPI @ 1.0
|-- DFRobot_BMP3XX @ 1.0.3
|   |-- SPI @ 1.0
|   |-- Wire @ 1.0
|-- ModbusMaster @ 2.0.1
|-- Adafruit TMP117 @ 1.0.1
|   |-- Adafruit BusIO @ 1.14.1
|   |   |-- Wire @ 1.0
|   |   |-- SPI @ 1.0
|   |-- Wire @ 1.0
|   |-- SPI @ 1.0
|   |-- Adafruit Unified Sensor @ 1.1.9
|-- ArduinoJson @ 6.21.2
|-- ArduinoOTA @ 1.0
|   |-- ESP8266WiFi @ 1.0
|   |-- ESP8266mDNS @ 1.2
|   |   |-- ESP8266WiFi @ 1.0
|-- ESP8266WiFi @ 1.0
|-- EspSoftwareSerial @ 8.0.1
|-- Wire @ 1.0
Building in release mode
Compiling .pio/build/esp8266/src/main.cpp.o
sh: 1: xtensa-lx106-elf-g++: not found
Generating LD script .pio/build/esp8266/ld/local.eagle.app.v6.common.ld
sh: 1: xtensa-lx106-elf-gcc: not found
Compiling .pio/build/esp8266/lib213/NTPClient/NTPClient.cpp.o
sh: 1: xtensa-lx106-elf-g++: not found
*** [.pio/build/esp8266/src/main.cpp.o] Error 127
Compiling .pio/build/esp8266/lib46a/ESP8266WiFi/BearSSLHelpers.cpp.o
*** [.pio/build/esp8266/ld/local.eagle.app.v6.common.ld] Error 127
*** [.pio/build/esp8266/lib213/NTPClient/NTPClient.cpp.o] Error 127
sh: 1: xtensa-lx106-elf-g++: not found
*** [.pio/build/esp8266/lib46a/ESP8266WiFi/BearSSLHelpers.cpp.o] Error 127
=================[FAILED] Took 6.14 seconds ========================

I tried deleting the directories in ~/.platformio/packages as well as the .cache folder, but the error still persists.

Does anyone know how to solve this problem? I am using Pio Core version is 6.1.6.

Thanks!

This error notoriously appears when there is a mismatch between what architecture the program was compiled for and what architecture your board / OS is using.

On a PlatformIO CLI (or just a regular CLI if you’ve installed it globally), what’s the output of

pio system info
uname -a
file ~/.platformio/packages/toolchain-xtensa/bin/xtensa-lx106-elf-g++
ldd ~/.platformio/packages/toolchain-xtensa/bin/xtensa-lx106-elf-g++

?

Are you using a 64-bit Raspbian or legacy 32-bit?

These are the outputs I got:

pio system info
PRETTY_NAME="Raspbian GNU/Linux 10 (buster)"
NAME="Raspbian GNU/Linux"
VERSION_ID="10"
VERSION="10 (buster)"
VERSION_CODENAME=buster
ID=raspbian
ID_LIKE=debian
HOME_URL="http://www.raspbian.org/"
SUPPORT_URL="http://www.raspbian.org/RaspbianForums"
BUG_REPORT_URL="http://www.raspbian.org/RaspbianBugs"
uname -a
Linux raspberrypi 5.10.103-v8+ #1529 SMP PREEMPT Tue Mar 8 12:26:46 GMT 2022 aarch64 GNU/Linux
file ~/.platformio/packages/toolchain-xtensa/bin/xtensa-lx106-elf-g++
/home/pi/.platformio/packages/toolchain-xtensa/bin/xtensa-lx106-elf-g++: ELF 64-bit LSB executable, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-aarch64.so.1, for GNU/Linux 3.7.0, BuildID[sha1]=83a4e38b38e9393266d5b6d2df4564d14edf1f20, stripped
ldd ~/.platformio/packages/toolchain-xtensa/bin/xtensa-lx106-elf-g++
not a dynamic executable

I am running the legacy 32-bit version of Raspberry Pi OS. Maybe this is causing the issue?

The interesting part is that the script was compiling because I updated the Rpi with sudo apt-get update && sudo apt-get upgrade.

Thank you for your response!

Well seems to be thinking you’re running on 64-bit. Since that’s also what the uname -a output suggests with

Where there’s no mention of 32-bits.

This is not the first time I’ve seen reports about such an error. The upgrade might have screwed with the identifaction of the system.

Can you test a new SD card that has the latest 64-bit rasbian on it?

You can see my issue, may be solution is same.

After updating 32 bit Raspi OS Pi 4 is on 64bit kernel