Skip to content

Instantly share code, notes, and snippets.

@justinmklam
Last active September 18, 2020 16:44
Show Gist options
  • Save justinmklam/df990e5093a48d1ffc30a9c91a9d270f to your computer and use it in GitHub Desktop.
Save justinmklam/df990e5093a48d1ffc30a9c91a9d270f to your computer and use it in GitHub Desktop.
Instructions to cross compile applications for target arm architecture.

The steps below provide a way to cross compile on your local development machine. Docker and QEMU to emulate the armhf/arm32v7 architecture.

Tested on:

  • Ubuntu 18.04 LTS

Prerequisites

Install dependencies on your local development machine:

sudo apt install docker qemu-user-static binfmt-support

# Start the docker daemon
sudo service docker start

Build the docker image:

sudo docker build -t arm32v7/debian .

Compiling the Application

Enter the docker image:

Note: The -v flag mounts the source code directory in the docker image, so any generated files (ie. the build outputs) will show up on your local filesystem.

# Start the docker image in interactive mode
sudo docker run -it -v $(pwd):/home/arm arm32v7/debian /bin/bash

Note: Any changes made to the local files will be reflected in the interactive docker image. ie. Source code can be edited and the docker shell can be left open to continually test for builds.

Once inside the docker image, build the printer application:

cd /home/arm/myrepo

make clean
# Build using all available processors/cores
make -j$(nproc)

After the build completes, you may exit the docker image with CTRL+D or by typing exit.

# armhf/debian is deprecated, so use arm32v7
FROM arm32v7/debian:stretch
MAINTAINER Justin Lam "[email protected]"
# List build dependencies here
RUN apt-get update && apt-get install -y build-essential
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment