Skip to content

Cross compile for raspberry PI

Jean-Michel DECORET edited this page Sep 23, 2016 · 32 revisions

This page explain how to cross compile yadoms on a linux computer and deploy executable to RaspberryPI. This wiki page has been tested with

  • Ubuntu 16.04 LTS

Before starting

  • RaspberryPI and Ubuntu are connected to network
  • SSH is activated on Raspberry

We assume user know:

  • Raspberry PI ip address
  • Raspberry sudoer account (login and password); i.e. : pi / raspberry

Install cross compiler

Before you start you need to make sure the following is installed:

apt-get install git

Start with making a folder in your home directory called raspberrypi. Go in to this folder and pull down the ENTIRE tools folder you mentioned above:

git clone --depth=1 git://github.com/raspberrypi/tools.git

The tools repository contains many toolchains. Go into your home directory , edit the file ~/.bashrc and add the following file at end:

export PATH=$PATH:$HOME/raspberry/tools/arm-bcm2708/arm-rpi-4.9.3-linux-gnueabihf/bin

Now you can either log out and log back in (i.e. restart your terminal session), or run . ~/.bashrc in your terminal to pick up the PATH addition in your current terminal session. Now, verify that you can access the compiler arm-linux-gnueabihf-gcc -v. You should get something like this:

arm-linux-gnueabihf-gcc --version
arm-linux-gnueabihf-gcc (crosstool-NG crosstool-ng-1.22.0-88-g8460611) 4.9.3
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Boost 1.61

Boost must be cross compiled because the apt-get do not provide all requested libraries.

Download boost_1_61_0.tar.bz2 from http://www.boost.org Extract it

	tar xjf boost_1_61_0.tar.bz2

Create bootstrap

	cd boost_1_61_0
	./bootstrap.sh

Create the user-config.jam in the user directory (cd ~)

	vi ~/user-config.jam

        using gcc : arm : arm-linux-gnueabihf-g++ ;

Cross compile boost (only useful libraries)

	./b2 --with-atomic --with-chrono --with-date_time --with-filesystem --with-regex --with-serialization --with-thread --with-system --no-samples --no-tests toolset=gcc-arm link=shared toolset=gcc-arm

Cross compile OpenSSL

Download the latest stable version of openssl

Version 1.0.x is working. Version 1.1.x is not working well

Extract the package

	tar xzf openssl-1.0.2e.tar.gz
apt-get source libunwind

Compile the sources


export cross=arm-linux-gnueabihf-

./Configure --prefix=/path/to/makeinstall/dist/openssl os/compiler:arm-linux-gnueabihf

make CC="${cross}gcc" AR="${cross}ar r" RANLIB="${cross}ranlib"

make install

Cross compile POCO

Download the POCO complete package from http://pocoproject.org/ (take the linux package)

Tested with : 1.6.1

Extract the package

	tar xzf poco-1.6.1-all.tar.gz

In order to make it cros compile, we need to define the RaspberriPI platform.

	cd poco-1.6.1-all
	cd build
	cd config
	cp ARM-Linux RaspberryPI

Edit the file RaspberryPI (with any text editr : vi, nano, gedit,...)

In general settings, remove the lines starting with "STLPORT" In general settings, change the tool

	TOOL               = arm-linux-gnueabihf

In System Specific Flags, remove the following flags

-I$(STLPORT_INCLUDE)

In System Specific Libraries, remove the following defines

-L$(STLPORT_LIB)

and

-lstlport_arm-linux-gcc

set the openssl directory to the openssl used prefix path (/path/to/makeinstall/dist/openssl in this page)

OPENSSL_INCLUDE    = /path/to/makeinstall/dist/include
OPENSSL_LIB        = /path/to/makeinstall/dist/lib

Save and return to poco root

	cd ../..

Configure POCO

./configure --config=RaspberryPI --no-samples --no-tests --omit=CppUnit,CppUnit/WinTestRunner,Data,Data/SQLite,Data/ODBCData/MySQL,MongoDB,PageCompiler,PageCompiler/File2Page
make -s

PCRE

Download pcre sources from http://www.pcre.org Take PCRE v1 (not v2) Extract it

./configure --host=arm-linux-gnueabihf CC=arm-linux-gnueabihf-gcc AR=arm-linux-gnueabihf-ar STRIP=arm-linux-gnueabihf-strip RANLIB=arm-linux-gnueabihf-ranlib --prefix=/path/to/makeinstall/dist/pcre
make
make install

Protobuf

In order to build with protobuf, you need to build and install it for host; then cross compile it.

Host protobuf is used to generate header file (with protoc) Cross compiled version is used to link with yadoms

For host

    sudo apt-get install autoconf libtool
    wget https://github.com/google/protobuf/releases/download/v2.6.1/protobuf-2.6.1.tar.gz
    tar -vxzf ./protobuf-2.6.1.tar.gz
    cd protobuf-2.6.1
    ./autogen.sh
    ./configure
    make
    sudo make install

Cross compilation

./configure --host=arm-linux CC=arm-linux-gnueabihf-gcc AR=arm-linux-gnueabihf-ar STRIP=arm-linux-gnueabihf-strip RANLIB=arm-linux-gnueabihf-ranlib --prefix=/home/jeanmichel/Bureau/raspberry/protobuf-2.6.1/rpi
make
sudo make install

Python

sudo apt-get install python python-dev

download python

Depending on the RaspberryPI, you must use the same python version For example, for Raspbian Jessy (2.7.9-1) , for Whezzy (2.7.3-4+deb7u1)

tar xzf Python-2.7.11.tgz

Build for system

cd Python-2.7.11/
./configure
make python Parser/pgen
mv python hostpython
mv Parser/pgen Parser/hostpgen	
make distclean

Cross compile

Adjust the first line "CC=...." to make path match to raspberrypi tools.

CC=/path/to/tools/arm-bcm2708/arm-rpi-4.9.3-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc CXX=/path/to/tools/arm-bcm2708/arm-rpi-4.9.3-linux-gnueabihf/bin/arm-linux-gnueabihf-g++ AR=/path/to/raspberry/tools/arm-bcm2708/arm-rpi-4.9.3-linux-gnueabihf/bin/arm-linux-gnueabihf-ar RANLIB=/path/to/raspberry/tools/arm-bcm2708/arm-rpi-4.9.3-linux-gnueabihf/bin/arm-linux-gnueabihf-ranlib ./configure --host=arm-linux --build=arm-linux-gnueabihf --prefix=/path/to/makeinstall/dist/python --disable-ipv6 ac_cv_file__dev_ptmx=no ac_cv_file__dev_ptc=no ac_cv_have_long_long_format=yes --enable-shared

make

make install

Postgresql (optional)

wget https://ftp.postgresql.org/pub/source/v9.4.2/postgresql-9.4.2.tar.bz2
tar xjf https://ftp.postgresql.org/pub/source/v9.4.2/postgresql-9.4.2.tar.bz2
cd postgresql-9.4.2
CC=/home/jeanmichel/Bureau/raspberry/tools/arm-bcm2708/arm-rpi-4.9.3-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc CXX=/home/jeanmichel/Bureau/raspberry/tools/arm-bcm2708/arm-rpi-4.9.3-linux-gnueabihf/bin/arm-linux-gnueabihf-g++ AR=/home/jeanmichel/Bureau/raspberry/tools/arm-bcm2708/arm-rpi-4.9.3-linux-gnueabihf/bin/arm-linux-gnueabihf-ar RANLIB=/home/jeanmichel/Bureau/raspberry/tools/arm-bcm2708/arm-rpi-4.9.3-linux-gnueabihf/bin/arm-linux-gnueabihf-ranlib ./configure --host=arm-linux --build=arm-linux-gnueabihf --prefix=/home/jeanmichel/Bureau/raspberry/pgsqlBuild --without-readline --without-zlib --disable-spinlocks
make
sudo make install

Swig

Install swig on the host

sudo apt-get install swig

CMake

	sudo apt-get install cmake

Yadoms

Clone sources

	git clone https://github.com/Yadoms/yadoms.git

Configure repo

Create the sources/CMakeListsUserConfig.txt (from the .sample.txt) ans edit the boost root configuration (don't forget to remove #)

set(BOOST_ROOT "/path/to/raspberry/boost/boost_1_58_0")
set(POCO_ROOT "/path/to/poco-1.6.0")

To cross compile for Raspberry PI, set the three defines

SET(CC_RPI_GCC arm-linux-gnueabihf-gcc)
SET(CC_RPI_GXX arm-linux-gnueabihf-g++)
SET(CC_RPI_LIBS /path/to/raspberry/git/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/arm-linux-gnueabihf/libc/usr/lib/arm-linux-gnueabihf/)

If something fails, try to specify full path for CC_RPI_GCC and CC_RPI_GXX

Generate makefile

	cd yadoms
	sh cmake_raspberry.sh c

Build Yadoms

To make using standard makefile:

	cd projects
	make

To make using "cotired" makefile (really much faster):

	cd projects
	make all_unity

Deploy Yadoms to Raspberry PI

Assume you know : pi_login : for this example : pi pi_address: 192.168.0.7

Create these directories on target where to copy files:

        ssh pi_login@pi_address
        mkdir /home/pi/dev/ccyadoms
        mkdir /home/pi/dev/ccyadoms/www
        mkdir /home/pi/lib_tmp
        exit

First step : copy yadoms executable

        cd yadoms
        cd build
        scp -r * pi_login@pi_address:/home/pi/dev/ccyadoms

Second step : copy shared files to target

As /usr/local/lib needs root rights, use the lib_tmp folder in home

        scp plugins/libyadoms-shared.so pi_login@pi_address:/home/pi/lib_tmp
        scp path/to/poco-1.6.0/lib/Linux/ARM/* pi_login@pi_address:/home/pi/lib_tmp
        scp path/to/boost_1_58_0/stage/lib/* pi_login@pi_address:/home/pi/lib_tmp

Third step : copy web site files to target

        scp -r www/* pi_login@pi_address:/home/pi/dev/ccyadoms/www

Endly, go to the target to move shared files to /usr/local/lib

        ssh pi_login@pi_address
        sudo mv lib_tmp /usr/local/lib
        rmdir lib_tmp
        exit

On the target, do a ldconfig to update available libraries

ssh pi_login@pi_address
sudo ldconfig

Workaround for a known bug (will be fixed) : make logs directory

mkdir logs

Run yadoms

./yadoms
Clone this wiki locally