« Previous - Version 22/27 (diff) - Next » - Current version
coder, 01/02/2016 23:18


This page explains how to install the libavg developer version from github on a Raspberry Pi by cross-compiling. The process involves compiling libavg on a separate Linux machine. The benefit of this is that compiling on the Pi 2 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. To compile directly on the Pi, install libSDL as explained below and then follow the UbuntuSourceInstall directions, passing --enable-rpi --enable-egl to configure.

Note that Raspberry Pi support is still beta - we're working on fixing all remaining issues. This is tested with Raspbian Wheezy.

Install dependencies on the Pi

On the Pi, install the needed packages:

$ sudo apt-get install libjpeg62-turbo-dev libjpeg-dev git automake autoconf libtool \
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 g++ libxxf86vm-dev libdc1394-22-dev linux-libc-dev

Install libSDL

$ sudo apt-get install 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


$ 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.4 from libsdl.org, unpack the tarball. Then build and install libSDL:

$ ./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

Set up the Cross-compile Toolchain

This work is done on the Linux machine.

This is the directory structure we'll need:

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

Tell the build system where the directory hierarchy is:

$ export AVG_RPI_ROOT=.....

Download the crosscompile tools to rpi-tools:

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

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

$ mkdir root
$ cd root
$ 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 directories. Open the files in a text editor and change them. They are:


GROUP ( libpthread.so.0 libpthread_nonshared.a )


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

Fix some symlinks:

$ cd root/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

Put the toolchain into the path (with $AVG_RPI_ROOT as set above):

$ export PATH=$PATH:$AVG_RPI_ROOT/rpi-tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin

Build libavg

Tell configure which architecture to build for. For Raspbian on the Pi 2:

$ export ARCHFLAGS="-mcpu=cortex-a7 -mfpu=neon-vfpv4" 

and for the older Pi:

$ export 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 ARCHFLAGS to.

Once you've set the architecture, check out libavg and build:

$ cd rpi
$ git clone https://github.com/libavg/libavg.git
$ cd libavg
$ ./bootstrap
$ ./rpi-configure
$ DESTDIR=$AVG_RPI_ROOT/staging make -j6
$ DESTDIR=$AVG_RPI_ROOT/staging make install

Install on the Pi

Copy the compiled libavg to the Pi:

$ cd ../staging
$ rsync -au usr pi@$IP:/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.