If you use macOS you might be able to use a cross-compilation environment that runs on macOS, but produces binaries that run on a RaspberryPI. Native speed and no VM's required! The environment consists of a disk image that contains a cross-platform toolchain created using crosstool-ng, and an rpi-root
folder containing necessary files from Raspbian Buster.
The cross-compiler was created based on instructions written by Jared Wolff. The OF side of the environment was based on jcleave's post on cross-compilers.
Compilation has only been tested on MacOS 10.14 using openFrameworks 0.10.1. Binaries produced are armv6 and have only been tested on a Raspbian Stretch and Buster on a RPi 2B. Running on earlier OS's will probably require updating libraries, but binaries should run on newer Pi models. armv7 binaries would require modifications of the appropriate OF makefile, which I have not done. Using older versions of OF will likely not work without some modifications to the provided makefile.
The idea behind the environment is to be able to compile an OF app directly from the source files located in your Mac, and to produce binaries that are stored in your Mac's OF app directory (inside a bin
folder, just like in Linux). You can then copy those binaries to your RPi for execution.
The following instructions assume that you are using a standard release of openFrameworks. If you are using OF from the repository these steps might be slightly different.
- Begin by downloading the zip file containing the disk image. The archive is about 2.6GB, but you'll need an additional 6.5GB of hard drive space to decompress it.
- Download and decompress the Linux armv6 release of openFrameworks (download 0.10.1 [here] (https://openframeworks.cc/versions/v0.10.1/of_v0.10.1_linuxarmv6l_release.tar.gz)), which we'll need to get some libraries that we'll copy to macOS.
- In Finder, open the macOS openFrameworks folder. Let's call this folder
<your_macOS_OF_Folder>
. - Now we'll copy the libraries necessary to link RPi apps to the libs folder of our OF release in macOS. In Finder, open the
libs
folder of the release you just downloaded. Copy the following:- The folder
kiss
to<your_macOS_OF_Folder>/libs
- The folder
tess2/lib/linuxarmv6l
to<your_macOS_OF_Folder>/libs/libstess2/lib/
- The folder
- Make a new folder called
linuxarmv6l
in<your_macOS_OF_Folder>/libs/openFrameworksCompiled/project/
- Mount the disk image you downloaded by double-clicking
xtools-build-env.sparsebundle
- Copy
/Volumes/xtools-build-env/extras/config.linuxarmv6l.default.mk
to the folder you created in step 5. - Now you need to modify your bash profile:
- In Terminal, type
nano ~/.bash_profile
. - Add the following lines to it:
- In Terminal, type
export GST_VERSION=1.0
export PLATFORM_OS=Linux
export PLATFORM_ARCH=armv6l
export PLATFORM_VARIANT=default
export RPI_ROOT=/Volumes/xtools-build-env/rpi-root
export TOOLCHAIN_ROOT=/Volumes/xtools-build-env/arm-unknown-linux-gnueabihf
export PKG_CONFIG_PATH=$RPI_ROOT/usr/lib/arm-linux-gnueabihf/pkgconfig:$RPI_ROOT/usr/share/pkgconfig:$RPI_ROOT/usr/lib/pkgconfig
export TOOLCHAIN_PREFIX=arm-unknown-linux-gnueabihf
export GCC_PREFIX=arm-linux-gnueabihf
export GCCVER=6
3. Save it by typing `cntrl+o` and then exit with `cntrl+x`.
4. Close the Terminal window.
- Ok, almost there! At this point you should try to compile an OF example:
- MAKE SURE THAT THE DISK IMAGE IS MOUNTED! None of this works without the disk image!
- Use the [Project Generator])https://openframeworks.cc/learning/01_basics/create_a_new_project/) to create the makefiles for any example.
- Open a new Terminal window in the folder of the example that you are using.
- Type the following command:
make PLATFORM_ARCH=armv6l Release -j4
- This should compile OF as well as the example, but it should end with a linking error mentioning something about
crti.o
andcrt1.o
not being found. THIS IS EXPECTED. If this is where you are, don't close the Terminal window and go to step 10.- If this is not the error you get then something has gone wrong. Check that the image is mounted and that you've added the correct lines to your ~/.bash_profile. If you need to modify your profile, save it and then open an new Terminal window to apply the changes (you can also use the
source
command to apply your profile by typing in your Terminal windowsource ~/.bash-profile
).
- If this is not the error you get then something has gone wrong. Check that the image is mounted and that you've added the correct lines to your ~/.bash_profile. If you need to modify your profile, save it and then open an new Terminal window to apply the changes (you can also use the
- Due to some mysterious reason that I don't understand AT ALL,
crti.o
,crt1.o
, andcrtn.o
, which are part of the toolchain and are necessary to link c++ programs, are not found by the linker. Because of this you need to copy them to your project folder, and to make this easier I have provided copies that are in/Volumes/xtools-build-env/extras
.- Copy
crti.o
,crt1.o
andcrtn.o
to your project folder. - In the Terminal window that you left open, type
make PLATFORM_ARCH=armv6l Release -j4
(or just press the up arrow to show the last command you typed). - If the compilation process completed, congratulations! You now have a shiny new executable in the
bin
folder of your project that should run on the Raspberry Pi!
- Copy
For any new project you want to cross-compile you'll need to copy crti.o
, crt1.o
and crtn.o
to your project's folder. Yes, unfortunately you have to do this for every project, but it is a small annoyance for a huge gain in convenience and performance. If you figure out how to fix this LET ME KNOW!!
trying it now.
2 things I am unsure about:
8. i. Is this .bash_profile a file in the current user root or in the OF folder?
9. ii. Do I select Platform OS X or Linux ARMv6 or both ?
Here is my console printout with all it's errors:
https://gist.github.com/stephanschulz/add4ea4541846603ef1aacd707df6e06
for example
/Volumes/xtools-build-env/arm-unknown-linux-gnueabihf/lib/gcc/arm-unknown-linux-gnueabihf/6.4.0/../../../../arm-unknown-linux-gnueabihf/bin/ld.bfd: cannot find -lm
also: