Cross-Compiling Fully Static ARMv5 Linux Binaries with a musl.cc Toolchain

Need a userspace binary for an ARMv5-only Linux device (e.g. MikroTik EN7562CT routers that only run arm32v5 containers)? musl.cc publishes ready-to-run cross toolchains — including an ARMv5 soft-float musl target — that produce fully static binaries requiring nothing but a Linux kernel.

Get the toolchain

tc.sh
mkdir -p ~/opt && cd ~/opt
curl -O https://musl.cc/armv5l-linux-musleabi-cross.tgz
tar -xzf armv5l-linux-musleabi-cross.tgz
~/opt/armv5l-linux-musleabi-cross/bin/armv5l-linux-musleabi-g++ --version
# -> GCC 11.2.1

armv5l-linux-musleabi = ARMv5TE, soft-float EABI, musl libc — no root needed, no package install, just untar.

Compile

build.sh
TC=~/opt/armv5l-linux-musleabi-cross/bin/armv5l-linux-musleabi
${TC}-g++ -march=armv5te -mfloat-abi=soft -O2 -static -o app app.cpp -latomic
  • -static → single self-contained ELF, runs in any container (no /lib/ld-musl-*.so needed)
  • -latomic → ARMv5 has no 8-byte atomics; __atomic_*_8 libcalls must resolve
  • Result: ELF 32-bit LSB executable, ARM, EABI5, statically linked

Why musl instead of glibc cross

  • glibc static linking is problematic (NSS, dlopen); musl is designed for it.
  • A static musl binary works in debian (glibc) containers, scratch containers, RouterOS — anywhere the kernel runs armv5.
  • Toolchain runs on x86_64 host at native compile speed — no qemu emulation needed for compiling.

Caveat

GCC 11.2.1 lacks <format>, <print>, <expected> — for C++23 codebases you need polyfills ({fmt}, tl::expected) or a newer toolchain.


Check out similar posts by category: C/C++ الأنظمة المدمجة Linux