This works for all versions of the Pi up to the 4.
- Clone this repo:
https://github.com/ab3lson/raspberry-pi-cross-compiler.git
- Download the Toolchain:
wget https://github.com/Pro/raspi-toolchain/releases/latest/download/raspi-toolchain.tar.gz
- Extract the toolchain:
sudo tar xfz raspi-toolchain.tar.gz --strip-components=1 -C /opt
- Create a folder in your home directory called rpi and put a rootfs folder inside:
mkdir -p ~/rpi/rootfs
- Copy your Pi's root filesystem with rsync to get all of its libraries (replace the IP with your Pi's IP):
rsync -vR --progress -rl --delete-after --safe-links [email protected]:/{lib,usr,opt/vc/lib} ~/rpi/rootfs
sudo apt install cmake
- Create a project folder for your C code
- Save code inside of the project folder
- Create a file called CMakeLists.txt inside of the project folder
- Create CMake file (using file in hello_world as a template)
- Run
rpi_cross_compile.sh
- If your code compiled successfully, it will be found inside the newly created
build
folder