Cross-Compilation and Sysroots
Build, host, and target machines; GNU triples; what a sysroot actually contains; CMake toolchain files and the find_root_path knobs; and testing cross-built binaries under QEMU.
Overview
Cross-compilation is the routine case
Embedded Linux, mobile, WebAssembly, Apple Silicon universal binaries and any multi-architecture CI matrix all produce binaries on a machine that cannot run them. It feels hard because build systems assume the compiler, the libraries it links and the machine running the result are the same box, and every layer where that assumption leaks must be corrected by hand.
The picture below is the whole job. A build machine, such as an x86-64 CI runner, uses a cross compiler and a sysroot to produce an aarch64 artifact. The artifact is deployed to the host machine, the device. Before it ships, you check it with readelf, run it under qemu-user and try it on real hardware.
Four hurdles stand between you and a correct artifact, and each one is a place where the 'same box' assumption leaks.
Key concepts
- Build / host / target
- GNU target triple
- Sysroot
- Toolchain file
- CMAKE_FIND_ROOT_PATH_MODE_*
- CMAKE_STAGING_PREFIX
- CMAKE_CROSSCOMPILING_EMULATOR
- Multiarch
Interview questions
- Write a CMake toolchain file for an aarch64 Linux target and explain every line.
- A colleague says the cross build works but the binary segfaults on the device. Walk through your diagnosis.
- How do you handle configure-time checks that need to run a program, when you cannot run target binaries?
- Compare the realistic ways to obtain a cross toolchain, and when you would pick each.
- Design a CI pipeline that builds and tests for three architectures from x86-64 runners.
Sign up free to read the full topic
More DevOps topics
- Container Runtime Security
- containerd and Container Runtimes
- Continuous Delivery vs Deployment
- Continuous Integration
- Control Plane Errors — API Server, RBAC, Webhooks, Quotas and Finalizers
- Cost-Optimized CI Runner Fleet
- Crossplane — Cloud Control Plane
- Dagger
- Data Observability
- Database Migrations in CI/CD
- Database Schema Evolution
- Debugging a Broken Alerting Pipeline
Start free on Cariara · Coding problems · System design studio