Skip to content

Cross Compiling for Raspberry Pi (Raspbian) and BeagleBone Black (Debian Stretch)

Günter Obiltschnig edited this page Sep 3, 2018 · 5 revisions

This article describes how to cross-compile macchina.io for a Raspberry Pi (2 or newer) running Raspbian Stretch or BeagleBone Black running Debian Stretch.

Prerequisites

A Debian Stretch host system (VM) with the following packages installed:

  • git
  • build-essential
  • libssl-dev
  • python
  • crossbuild-essential-armhf

Preparing the Host System

First we need to prepare the package manager to install packages required for cross-compiling. For example, the OpenSSL headers and libraries must be available for the armhf architecture.

$ sudo dpkg --add-architecture armhf
$ sudo apt-get update

Install the essential packages for building the host tools:

$ sudo apt-get install build-essential libssl-dev python 

Install the packages required for cross-compiling:

$ sudo apt-get install crossbuild-essential-armhf
$ sudo apt-get install libssl-dev:armhf

Building macchina.io

Get macchina.io Sources from GitHub

$ git clone https://github.com/macchina-io/macchina.io.git

Build the Host Tools

This will build the tools (e.g., BundleCreator) required for building macchina.io.

$ cd macchina.io
$ make -s -j8 hosttools

This takes a couple of minutes. Note: Depending on the number of CPU cores you have on your build machine, adjust the -j8 argument accordingly.

Build for Target

In order to build for the target, a build configuration file must be used. You can find various build configuration files in platform/build/config. The build configuration for BeagleBone Black running Debian Stretch is called X-Debian-Stretch-BBB. The one for a Raspberry Pi running Raspbian Stretch is called X-Debian-Stretch-RPi.

The POCO_CONFIG environment (or Makefile) variable should contain the name of the build configuration to use. Therefore, we run:

$ POCO_CONFIG=X-Debian-Stretch-BBB make -s -j8 DEFAULT_TARGET=shared_release

to build macchina.io for the target. The DEFAULT_TARGET=shared_release argument instructs the build system to build the release executables only. If omitted, the build system would build both debug and release executables.

For a Raspberry Pi, the command would be:

$ POCO_CONFIG=X-Debian-Stretch-RPi make -s -j8 DEFAULT_TARGET=shared_release

Depending on build machine performance, this takes 20-30 minutes.

Create Tarball for Transfer to Target

To build a directory structure and tarball that can be easily transferred to the target device (e.g., via scp), use the install_runtime make target:

$ POCO_CONFIG=X-Debian-Stretch-BBB make -s install_runtime INSTALLDIR=/home/admin/macchina_runtime

This will create the following directory structure:

macchina_runtime/
    lib/
        bundles/
    bin/
    etc/

Then, pack the macchina_runtime directory into a tarball:

$ tar cfz macchina_runtime.tgz /home/admin/macchina_runtime

Running macchina.io on the Target

Copy the tarball to the target (e.g., using scp) and expand it with:

$ tar xfz macchina_runtime.tgz

Before starting macchina.io, you have to set the LD_LIBRARY_PATH environment variable, so that the macchina.io shared libraries (both in the lib directory and in the codeCache) will be found.

$ export LD_LIBRARY_PATH=/path/to/macchina_runtime/lib:/path/to/macchina_runtime/bin/codeCache

You should also create the codeCache directory before you start macchina.io, so that the dynamic linker will find it. Otherwise, the first start of macchina.io may fail.

$ mkdir /path/to/macchina_runtime/bin/codeCache

Then you can start macchina.io:

$ /path/to/macchina_runtime/bin/macchina --config=/path/to/macchina_runtime/etc/macchina.properties