Cross-compiling: building for an ARM board on a PC
A toolchain that builds executables for another architecture on a powerful PC. The sysroot and library versions have to match for it to run on the board.
Why cross-compile
Building directly on an embedded board is slow and short of storage. You build an ARM executable on an x86 PC and move it to the board.
Toolchain names
aarch64-linux-gnu-gcc = target architecture (aarch64) - operating system (linux) - ABI (gnu) - tool (gcc)
| Target | Example toolchain |
|---|---|
| 64-bit ARM Linux | aarch64-linux-gnu- |
| 32-bit ARM Linux (hard float) | arm-linux-gnueabihf- |
| MCU (no operating system) | arm-none-eabi- |
aarch64-linux-gnu-gcc -o hello hello.c
file hello # ELF 64-bit LSB executable, ARM aarch64
scp hello root@board:/tmp/
RoadmapSee where this note sits in Embedded Linux→sysroot
The bundle of the board's header files and libraries. Build against a newer glibc than the one installed on the board and you get an error such as "GLIBC_2.34 not found". Use the toolchain and sysroot from the SDK produced by the Yocto/Buildroot build that made the board image, and they match.
Build systems
In CMake, a toolchain file names the compiler and sysroot. Connect the GDB server on the board (gdbserver) with gdb-multiarch on the PC and you can debug remotely too.