Home avatar

A collection of dev guides, tutorials and thoughts on various tech stacks, tools and programming languages.

Cross compile for Raspberry Pi with Docker

The Raspberry Pi is a popular platform for prototyping IoT products, simulating embedded environments, or running lightweight clusters.

Developing software in C or C++ for the Raspberry Pi presents several workflow choices:

  1. Building directly on the board via SSH, git, or rsync.
  2. Building within emulated containers on the board (which introduces significant latency when interfacing with camera and hardware peripherals).
  3. Using crosstool-ng to generate a local toolchain.
  4. Using Docker and multi-stage builds to cross-compile from any host machine without needing physical hardware.

Cross-compiling with Docker Buildx offers consistent builds across macOS, Linux, and Windows, requires zero setup on the target Raspberry Pi, and exports native ARM binaries directly to your local filesystem.

How to install cmake?

CMake is a cross-platform tool for building, testing and packaging software.

If you’ve been writing C or C++ (or Fortran) you probably had to, at some point, use cmake to package your software.

On macOS, the recommended method is using Homebrew:

brew install cmake

Or download the macOS .dmg installer directly from the CMake download page.