« Previous - Version 25/27 (diff) - Next » - Current version
scotty, 03/05/2017 21:40


RaspberryPiSourceInstall

This page explains how to install the libavg developer version from github on a Raspberry Pi by either native or cross compiling. The latter involves compiling libavg on a separate Linux machine. The benefit of this is that native compiling on the Pi 2/3 takes around an hour, while cross compiling takes a few minutes (The original Pi would finish in 4-6 hours or fail with an out of memory condition). The downside is that it's a bit harder to set up.

Tested on Pi 2/3 with 2017-04-10-raspbian-jessie, cross compiling on ubuntu-16.04.2-desktop-amd64.

To enable architecture specific optimizations, compiler flags can be provided. Just add them to the cmake calls below. (However, they don't seem to make much of a difference.)

For Raspbian on the Pi 3:

-DAVG_RPI_ARCHFLAGS="-mcpu=cortex-a53 -mfpu=neon-vfpv4"

on the Pi 2:

-DAVG_RPI_ARCHFLAGS="-mcpu=cortex-a7 -mfpu=neon-vfpv4"

and for the older Pi:

-DAVG_RPI_ARCHFLAGS="-march=armv6 -mfloat-abi=hard -mfpu=vfp"

For other distros, run gcc -mcpu=native -march=native -Q --help=target on the Pi to find out what to set AVG_RPI_ARCHFLAGS to.

Note that Raspberry Pi support is still beta - we're working on fixing all remaining issues.

Install libSDL

To build and run libavg on a Pi, libSDL2>=2.0.4 is needed. As current raspbian ships version 2.0.2, manual installation on the Pi is required.

$ sudo apt-get install automake autoconf libtool libfreeimage-dev libopenal-dev \
libsndfile-dev libudev-dev libasound2-dev libtiff5-dev libwebp-dev

On Wheezy, libevdev-dev isn't available, so add the following line to /etc/apt/sources.list:

deb http://http.debian.net/debian wheezy-backports main

Then:

$ sudo apt-get -t wheezy-backports install libevdev-dev

Say 'Y' to the 'Install without verification' prompt.

On Jessie, just install libevdev-dev:

$ sudo apt-get install libevdev-dev

Download libSDL 2.0.5 from libsdl.org, unpack the tarball. Then build and install libSDL:

$ wget https://www.libsdl.org/release/SDL2-2.0.5.tar.gz
$ tar -xzf SDL2-2.0.5.tar.gz 
$ cd SDL2-2.0.5
$ ./configure --host=armv7l-raspberry-linux-gnueabihf --disable-pulseaudio --disable-esd --disable-video-mir --disable-video-wayland --disable-video-x11 --disable-video-opengl
$ make -j5
$ sudo make install

Install dependencies on the Pi (for native and cross compiling)

On the Pi, install the needed packages:

$ sudo apt-get install libjpeg62-turbo-dev libjpeg-dev libxml2-dev \
libpango1.0-dev librsvg2-dev libgdk-pixbuf2.0-dev libavcodec-dev \
libavformat-dev libswscale-dev libavresample-dev python-dev libboost-python-dev \
libboost-thread-dev libxxf86vm-dev libdc1394-22-dev linux-libc-dev libxi-dev

Native compiling on the Pi

Install some build tools:

$ sudo apt-get install git cmake g++

Check out libavg and build:

$ git clone https://github.com/libavg/libavg.git
$ cd libavg
$ git checkout feature/raspi_jessie
$ mkdir build
$ cd build
$ cmake -DAVG_ENABLE_EGL=TRUE -DAVG_ENABLE_RPI=TRUE ..
$ make
$ make check
$ sudo make install

Note that the available RAM is the bottleneck here and things are getting very slow when the kernel starts swapping. Parallel builds with make -jx will fail with an out of memory error. It is suggested to free as much RAM as possible for the build process (e.g. by setting the GPU memory to 16 MB and booting only into the console, not X).

Cross compiling on a Linux host

This work is done on the Linux machine.

This is the directory structure we'll end up with:

rpi
    libavg        - the libavg source tree
    rootfs        - (partial) copy of the Pi root filesystem
    tools         - the toolchain (compiler, linker, etc.) used to cross compile
    staging       - the compiled version of libavg that will be copied to the Pi

Install some build tools:

$ sudo apt-get install git cmake

Tell the build system where the directory hierarchy is:

$ mkdir rpi
$ cd rpi
$ export AVG_RPI_PATH=$PWD

Set up the cross compile toolchain

Download the cross compile tools to rpi/tools:

$ cd rpi
$ git clone git://github.com/raspberrypi/tools.git

Copy /usr, /lib, and /opt/vc directory trees from the Pi to rpi/rootfs (replace $PI with the IP address of the Pi):

$ cd rpi
$ mkdir rootfs
$ cd rootfs
$ rsync -rl --delete-after --safe-links pi@$PI:/{lib,usr} .
$ rsync -rl --delete-after --safe-links pi@$PI:/opt/vc opt

Then, fix some system libraries so they don't contain references to absolute paths. Open the files in a text editor and change them. They are:

rootfs/usr/lib/arm-linux-gnueabihf/libpthread.so:

OUTPUT_FORMAT(elf32-littlearm)
GROUP ( libpthread.so.0 libpthread_nonshared.a )

rootfs/usr/lib/arm-linux-gnueabihf/libc.so:

OUTPUT_FORMAT(elf32-littlearm)
GROUP ( libc.so.6 libc_nonshared.a  AS_NEEDED ( ld-linux-armhf.so.3 ) )

Adjust the pkg-config file rootfs/usr/lib/arm-linux-gnueabihf/pkgconfig/glib-2.0.pc to have -lpcre in Libs, not in Libs.private:

[...]
Libs: -L${libdir} -lglib-2.0 -lpcre
Libs.private: -pthread     
[...]

Fix some symlinks:

$ cd rootfs/usr/lib/arm-linux-gnueabihf/
$ ln -s ../../../lib/arm-linux-gnueabihf/libm.so.6 libm.so
$ ln -s ../../../lib/arm-linux-gnueabihf/libdl.so.2 libdl.so

Check out and build libavg

$ cd rpi
$ git clone https://github.com/libavg/libavg.git
$ cd libavg
$ git checkout feature/raspi_jessie 
$ mkdir build
$ cd build
$ cmake -DCMAKE_TOOLCHAIN_FILE=../rpi-toolchain.cmake -DAVG_ENABLE_EGL=TRUE -DAVG_ENABLE_RPI=TRUE ..
$ make -j5
$ make install

Install on the Pi

Copy the compiled libavg to the Pi:

$ cd rpi/staging
$ mv usr/local/lib/python2.7/site-packages usr/local/lib/python2.7/dist-packages
$ rsync -au usr pi@$PI:/home/pi/Desktop

Back on the Pi, copy libavg from the desktop to its final destination:

$ sudo cp -R ~/Desktop/usr/* /usr

Run the tests

$ cd /usr/local/lib/python2.7/dist-packages/libavg/test/
$ python Test.py

That's it! libavg should now be running on your Pi.