Failing to compile using pio in termux

Hi all, sorry for my first post being a question like this.

I’ve been trying to compile a project inside termux; I’ve went down to having a super simple setup just to try faster, the libs I need for the project itself and this main.cpp:

cat src/main.cpp
#include <Arduino.h>
#include <SD_MMC.h>

// put function declarations here:
int myFunction(int, int);

void setup() {
  // put your setup code here, to run once:
  int result = myFunction(2, 3);
}

void loop() {
  // put your main code here, to run repeatedly:
}

// put function definitions here:
int myFunction(int x, int y) {
  return x + y;
}

For starters, this is my platformio.ini:

cat platformio.ini
; PlatformIO Project Configuration File                                                                                                                                                   ; Build, upload, library, and advanced options for the project.
; Documentation: url redacted

[env:dfrobot_firebeetle2_esp32s3]
platform = espressif32
board = dfrobot_firebeetle2_esp32s3
framework = arduino

; Library Dependency Finder (LDF) mode
lib_ldf_mode = deep

; Libraries
lib_deps =
    bxparks/AceButton@^1.10.1
    densaugeo/base64@^1.4.0
    espressif/esp32-camera@^2.0.4
    dfrobot/DFRobot_GDL@^1.0.1
    bodmer/TJpg_Decoder@^1.1.0
    adafruit/Adafruit Fingerprint Sensor Library@^2.1.3
    SPI
    SD_MMC
    Wire
    bblanchon/ArduinoJson@^7.2.0
    tzapu/WiFiManager@^2.0.17

I’ve checked just in case, to be sure there was nothing missing, running pio pkg install, here is the output:

pio pkg install
Resolving dfrobot_firebeetle2_esp32s3 dependencies...
Already up-to-date.

And now, when I try to compile it, this is the output:

pio run
Processing dfrobot_firebeetle2_esp32s3 (platform: espressif32; board: dfrobot_firebeetle2_esp32s3; framework: arduino)
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/espressif32/dfrobot_firebeetle2_esp32s3.html
PLATFORM: Espressif 32 (6.9.0) > DFRobot Firebeetle 2 ESP32-S3
HARDWARE: ESP32S3 240MHz, 320KB RAM, 4MB Flash
DEBUG: Current (cmsis-dap) External (cmsis-dap, esp-bridge, esp-builtin, esp-prog, iot-bus-jtag, jlink, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny, tumpa)
PACKAGES:
 - framework-arduinoespressif32 @ 3.20017.0 (2.0.17)
 - tool-esptoolpy @ 1.40501.0 (4.5.1)
 - toolchain-riscv32-esp @ 8.4.0+2021r2-patch5
 - toolchain-xtensa-esp32s3 @ 8.4.0+2021r2-patch5
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ deep, Compatibility ~ soft
Found 40 compatible libraries
Scanning dependencies...
Dependency Graph
|-- AceButton @ 1.10.1
|-- base64 @ 1.4.0
|-- DFRobot_GDL @ 1.0.1
|-- TJpg_Decoder @ 1.1.0
|-- Adafruit Fingerprint Sensor Library @ 2.1.3
|-- SPI @ 2.0.0
|-- SD_MMC @ 2.0.0
|-- Wire @ 2.0.0
|-- ArduinoJson @ 7.2.0
|-- WiFiManager @ 2.0.17
Building in release mode
Compiling .pio/build/dfrobot_firebeetle2_esp32s3/src/main.cpp.o
sh: 1: xtensa-esp32s3-elf-g++: not found
*** [.pio/build/dfrobot_firebeetle2_esp32s3/src/main.cpp.o] Error 127
Compiling .pio/build/dfrobot_firebeetle2_esp32s3/libf64/AceButton/ace_button/AceButton.cpp.o
sh: 1: xtensa-esp32s3-elf-g++: not found
*** [.pio/build/dfrobot_firebeetle2_esp32s3/libf64/AceButton/ace_button/AceButton.cpp.o] Error 127

I’ve tried:

  • installing pio core downloading and running the python script, also tried directly from pip
  • installing esp-idf manually too, running the install.py scripts inside as well, sourcing the variable’s file…

Doesn’t matter what I’ve done, it fails over and over by failing to run/find xtensa-esp32s3-elf-g++.

I am not sure what I am doing wrong, perhaps is not even supposed to work…

Am I missing something?

pio system info                                                                                                                                                                       --------------------------  ---------------------------------------------------------------------
PlatformIO Core             6.1.16
Python                      3.12.7-final.0
System Type                 linux_aarch64
Platform                    Linux-5.15.123-android13-8-28577532-abX816BXXS4BXG7-aarch64-with-libc
File System Encoding        utf-8
Locale Encoding             utf-8                                                                                                                                                         PlatformIO Core Directory   /data/data/com.termux/files/home/.platformio
PlatformIO Core Executable  /data/data/com.termux/files/home/.platformio/penv/bin/platformio                                                                                              Python Executable           /data/data/com.termux/files/home/.platformio/penv/bin/python
Global Libraries            0
Development Platforms       1
Tools & Toolchains          5
--------------------------  ---------------------------------------------------------------------

Thank you in advance

Seems like you’re trying to run on an Android ARM64 device.

The sh: 1: xtensa-esp32s3-elf-g++: not found is indicative for the compiler not being binary compatible, or having a wrong interpreter path (“the Linux kernel / the dynamic loader”) or having a missing library, so let’s work on that.

Can you open a terminal and do

cd /data/data/com.termux/files/home/.platformio/packages/toolchain*esp32*
cd bin
./xtensa-esp32s3-elf-g++ --version
ldd ./xtensa-esp32s3-elf-g++
readelf -a xtensa-esp32s3-elf-g++ | grep interpreter
readelf -a $(which cat) | grep interpreter

Hi Max, thanks for jumping in!

here is the output:

cd /data/data/com.termux/files/home/.platformio/packages/toolchain*esp32*
cd bin
./xtensa-esp32s3-elf-g++ --version
ldd ./xtensa-esp32s3-elf-g++
readelf -a xtensa-esp32s3-elf-g++ | grep interpreter
readelf -a $(which cat) | grep interpreter
bash: ./xtensa-esp32s3-elf-g++: cannot execute: required file not found
        libstdc++.so.6 => not found
        libm.so.6 => not found
        libc.so.6 => not found
      [Requesting program interpreter: /lib/ld-linux-aarch64.so.1]
      [Requesting program interpreter: /system/bin/linker64]

I’ve tried to install the missing libs but no joy so far

Ok I managed to get it running, but it is hackish…

Step 1: Install proot and proot-distro

pkg install proot proot-distro

Step 2: install and enter the ubuntu environment

proot-distro install ubuntu
proot-distro login ubuntu

Step 3: install the librariies (inside proot environment)

apt update && apt install -y libstdc++6 libc6

Step 4: install platformio again (inside proot environment)

pip install platformio

Step 5: copy the project into proot environment and run

pio run --target clean #will take a while, will download toolchain and others
pio run #as usual

And works!

Now I will try to reproduce it with a clean termux installation, see if Acode still works with it (and the proot environment) and I’ll have a way to program and compile with Platformio on my Android tablet (without root!).

Thank you for the hints @maxgerhardt !, if I find a simpler way to do it I’ll update this (if not closed for answering)

Great that you found a way.

It indeed seemd to be the primary problem here that the your Android system uses a by default different interpreter (/system/bin/linker64) and then that it… doesn’t have the regular glibc library like libc.so.6? Although it claims to be Linux-5.15.123-android13-8-28577532-abX816BXXS4BXG7-aarch64-with-libc , which is weird.

You can experiment with setting a different interpreter with patchelf --set-interpreter and maybe that’ll get you further.

Espressif compiles these “aarch64” binaries, but likely with a compiler like gcc-aarch64-linux-gnu that is targeted to run on, maybe a 64-bit Raspberry Pi, not on an AArch64 android phone. One could probably, with much effort, recompile the esp32s3 compiler with the right compiler for your target phone / environment, but that’s for sure gonna take a lot of figuring it out.

So, installing a Ubuntu like enviornment to make the interpreter and libraries all appear seems to be a good solution.