Ground Embedded KO Subscribe

Notes / Embedded Linux

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.

GROUND EMBEDDED · NOTEEmbedded Linux 02Cross-compiling 1$ make ARCH=arm 2$ insmod gnd_gpio.ko 3[ 1.024] gnd: probe ok 4$ cat /dev/gnd0 50x5A 6$ _

Why cross-compile

PC (x86)source codeCross compilerarm-linux-gnueabihf-gccARM executableRuns on the board
Build on the fast PC, run on the board.

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.

FREE PDFGet the 3 free ebooksIf you want to keep reading this topic as one book: BLDC motor control, serial communication and sensors at book length. PDFs are in Korean.Get them free →