User Tools

Site Tools


programming:rust:pi_compile

Cross-compile for Raspberry Pi 4

Overview

I've found a number of how-tos on the net about cross-compiling for the Raspberry Pi. None of them worked as the compile targets/tools were wrong. Here's what worked for me. The target boxes in this case are running 64 bit versions of Ubuntu 22.04.

I'm doing all the building on Ubuntu 22.04 x86_64

Install the Rust Target

The target you are wanting to install is aarch64-unknown-linux-gnu.

rustup target add aarch64-unknown-linux-gnu

Install the Necessary Build Tools

You'll actually need to install the appropriate build tools, specifically for the linking portion of the build.

sudo apt install g++-12-aarch64-linux-gnu

Set the Linker in Your Cargo Project

In the root of your Rust project you want to build (where your Cargo.toml file is), do the following:

# You have to create a build config with the linker set appropriately
mkdir .cargo
cat <<"EOF" > .cargo/config.toml
[build]
 
[target.aarch64-unknown-linux-gnu]
linker = "aarch64-linux-gnu-g++-12"
EOF
 
# Now you can build!
cargo build --release --target aarch64-unknown-linux-gnu
programming/rust/pi_compile.txt · Last modified: 2023/07/09 22:21 by jay