</>EmbeddedInterview

What is cross-compilation and what is a toolchain?

EasyEmbedded Linux & Boot

Short answer: Cross-compiling means building on one machine (the host, e.g. an x86-64 PC) a program that runs on a different architecture (the target, e.g. an ARM64 board). A toolchain is the set of tools and libraries that make this possible: cross compiler, assembler, linker, binutils, the C library and kernel headers for the target.

Why cross-compile: the target is often too slow, has too little RAM/storage, or has no compiler at all. Building a kernel on a quad-core Cortex-A53 takes hours; on a PC it takes minutes.

Toolchain triplets (the prefix tells you the target)

Prefix Target
aarch64-linux-gnu- 64-bit Arm, Linux, glibc
arm-linux-gnueabihf- 32-bit Arm, Linux, hard-float ABI
arm-none-eabi- bare-metal Arm (Cortex-M), no OS, newlib
riscv64-linux-gnu- 64-bit RISC-V, Linux
x86_64-linux-gnu- native PC
aarch64-linux-gnu-gcc -O2 -o hello hello.c
file hello        # ELF 64-bit LSB executable, ARM aarch64
make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- defconfig Image dtbs

What is in a toolchain

  • gcc/clang – compiler for the target.
  • as, ld, objcopy, objdump, readelf, nm, strip, addr2line – binutils.
  • C library (glibc/musl/newlib) and kernel headers that match the target kernel's userspace API.
  • gdb (cross) for remote debugging with gdbserver.

Sysroot: a directory with the target's headers and libraries (--sysroot=...). Linking against the sysroot ensures the binary uses the same library versions as the target, not the host's.

Getting a toolchain: distro packages, Arm GNU Toolchain releases, Bootlin toolchains, or the SDK generated by Yocto (bitbake -c populate_sdk) or Buildroot (make sdk). Using the build system's SDK guarantees it matches the image.

Classic mistakes: linking against host libraries (missing sysroot), mismatched glibc version ("GLIBC_2.34 not found" on the target), wrong float ABI on 32-bit Arm (hard-float vs soft-float), and forgetting ARCH= when building the kernel.