Build Cross Compile Tools for Raspberry Pi (Raspbian Stretch) on macOS
This guide is based on this article.
Written and tested with:
- Raspberry Pi 3 B+
- Raspbian Stretch (GCC 6.3.0 20170516)
- macOS 10.13.3
- clang+llvm 6.0.0
- binutils 2.30
Create a SDK directory
Create a SDK directory for not messing other things up:
Download / Install Tools
Now come back to the initial directory:
Copy Header/Library Files from Raspberry Pi
Let’s copy header and library files from Raspberry Pi over the network with
Create a Wrapper Shell Script for Cross Compiling
Open a new file,
and fill it with following lines:
then grant executable permission to it:
hello.c file with following content:
then build it with the shell script:
If nothing goes wrong, a file named
hello would be generated.
Upload it to the Raspberry Pi and run with:
then it will print out:
If any error occures while building, try again with
-v option to see what went wrong:
You may have to change the version number of COMPILER_PATH in your shell script, or install some packages on Raspberry Pi and copy header/library files again.
Building large projects or binaries on Raspberry Pi is painful; it often goes unresponsive and even crashes sometimes.
With this cross compilation tools, I will try building TensorFlow or Haskell packages like ghc-mod.
Will post about it if I see some progress :-)