Native Build of Qt 5.4.1 on a Raspberry Pi

From Qt Wiki
Revision as of 10:14, 7 April 2015 by Jmechnich (talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

This is an update to the wiki page Native_Build_of_Qt5_on_a_Raspberry_Pi using a Raspberry Pi 2 and a Qt source tarball. At the time of writing, access to the Qt source repository seemed flaky and the procedures found on the original instructions page didn't seem to be compatible with the current structure of the code.

In the following, a working setup for using Qt on the linux console with EGLFS and a touchscreen is established.

Compilation took ~8 hours without overclocking the Pi 2 which can be attributed to

  • compiling the source on an external USB HDD (in contrast to the very slow SD card), and
  • making use of the Raspberry Pi 2's multicore CPU.

In addition to the configuration used in Native_Build_of_Qt5_on_a_Raspberry_Pi, support for

  • tslib (touchscreen interface)
  • pkg-config

have been added.


For the following steps we asume that

  • the build is done for user pi locally
  • the Qt tarball has been downloaded to ~/qt-everywhere-opensource-src-5.4.1.tar.gz
  • an external USB HDD is available and can be mounted to /media/usb
  • the Qt binaries should be installed to /usr/local/qt5

Unpacking source to an external USB HDD

Using this method the tree will still be located logically in the user's home directory so that it can be moved there after compilation finished and the external USB HDD removed.

sudo mkdir -p /media/usb
# put proper device here instead of /dev/sdXX!
sudo mount /dev/sdXX /media/usb
sudo mkdir /media/usb/build
sudo chown pi /media/usb/build
cd /media/usb/build
tar zxvf ~/qt-everywhere-opensource-src-5.4.1.tar.gz

# now bind it to ~/opt/qt-everywhere-opensource-src-5.4.1
mkdir ~/opt/qt-everywhere-opensource-src-5.4.1
sudo mount --bind /media/usb/build/qt-everywhere-opensource-src-5.4.1 /home/pi/opt/qt-everywhere-opensource-src-5.4.1
cd ~/opt/qt-everywhere-opensource-src-5.4.1

Increasing available RAM for concurrent compilation

Although the Raspberry Pi 2 comes with 1 GB of RAM, this still isn't enough for compiling QtWebkit with more than one concurrent compilation process. By default, raspbian maintains a 100 MB swapfile. Assuming that the external USB HDD has sufficient size, a larger swapfile will be put there. Alternatively, a swap partition could have been used.

# disable and remove swap file
sudo dphys-swapfile swapoff
sudo dphys-swapfile uninstall

# edit /etc/dphys-swapfile to read
#  CONF_SWAPFILE=/media/usb/swap

# create and enable new swap file
sudo dphys-swapfile setup
sudo dphys-swapfile swapon

# check that a ~2GB swap file is active now
cat /proc/swaps

Configure and compile Qt source code

Installing prerequisites

sudo apt-get update
sudo apt-get dist-upgrade
sudo apt-get install libfontconfig1-dev libdbus-1-dev libfreetype6-dev libudev-dev libicu-dev \
 libsqlite3-dev libxslt1-dev libssl-dev libasound2-dev libavcodec-dev libavformat-dev libswscale-dev \
 libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev gstreamer-tools gstreamer0.10-plugins-good \
 gstreamer0.10-plugins-bad libraspberrypi-dev libpulse-dev libx11-dev libglib2.0-dev libcups2-dev \
 freetds-dev libsqlite0-dev libpq-dev libiodbc2-dev libmysqlclient-dev firebird-dev libpng12-dev \
 libjpeg62-dev libgst-dev libxext-dev libxcb1 libxcb1-dev libx11-xcb1 libx11-xcb-dev libxcb-keysyms1 \
 libxcb-keysyms1-dev libxcb-image0 libxcb-image0-dev libxcb-shm0 libxcb-shm0-dev libxcb-icccm4 \
 libxcb-icccm4-dev libxcb-sync0 libxcb-sync0-dev libxcb-render-util0 libxcb-render-util0-dev \
 libxcb-xfixes0-dev libxrender-dev libxcb-shape0-dev libxcb-randr0-dev libxcb-glx0-dev libxi-dev \
 libdrm-dev flex ruby gperf bison libts-dev
sudo apt-get clean

Configuring the Qt source

In contrast to the original wiki article, no manual adjustment of files seems to be necessary in order to properly build Qt on the Raspberry Pi. Not all functionality and modules were tested though, so YMMV.

./configure -v -opengl es2 -tslib -force-pkg-config -device linux-rasp-pi-g++ -device-option CROSS_COMPILE=/usr/bin/ \
 -opensource -confirm-license -optimized-qmake -reduce-exports -release -qt-pcre -make libs \
 -prefix /usr/local/qt5 2>&1 | tee config.out

Make sure that configuration succeeded. Look closely at the output from all errors as some features might be quietly disabled.


Although the Raspberry Pi 2 provides four CPU cores, using all of them proved to be slightly unstable despite of the measures taken at the top of this page. Using three of them worked fine and led to a satisfactory compilation time.

time make -j3 2>&1 | tee make.out

Installation and Cleanup


sudo make install

For using the installed version of Qt, it is convenient to have a setup file, e.g. ~/, which can be source'd if necessary. It should contain at least the following lines for setting up path variables:

export LD_LIBRARY_PATH=/usr/local/qt5/lib
export PATH=/usr/local/qt5/bin:$PATH

Additionally, it can be convenient to set additional variables depending on the periphery devices connected to the Pi, i.e. a touchscreen:

# hides mouse cursor
# enables tslib plugin for touch screen
# disables evdev mouse input (to avoid getting duplicated input from tslib AND evdev)
# set physical display dimensions for proper font sizes etc.
# Qt should print a warning if this is necessary

Cleaning up

Now some of the steps from #Preparation could be reversed:

# unbind source directory and copy source tree to SD card
sudo unmount /home/pi/opt/qt-everywhere-opensource-src-5.4.1
rsync -av /media/usb/build/qt-everywhere-opensource-src-5.4.1/ /home/pi/opt/qt-everywhere-opensource-src-5.4.1
# sudo rm -rf /media/usb/build

# revert to small swap file on SD card
sudo dphys-swapfile swapoff
sudo dphys-swapfile uninstall
# if the last step fails, continue with the following steps
# everything should be fine after a reboot
# the swap file has to be deleted manually after that though

# edit /etc/dphys-swapfile to read

# create and enable new swap file
sudo dphys-swapfile setup
sudo dphys-swapfile swapon

Additional Remarks

Up-to-date tslib support

At the time of writing, the raspbian package for tslib did not support all popular touchscreen controllers used with the Raspberry Pi, in particular the D-WAV Scientific Co., Ltd eGalax TouchScreen (from lsusb). As the library is plugin based, it could be updated without recompiling Qt.

git clone git://
cd tslib
make -j4
sudo make install

Unfortunately, the libts-0.0-0 package from Raspbian cannot be removed easily without breaking dependencies, so some 'hacking' has to be done:

mkdir tslib_backup
sudo mv /usr/lib/arm-linux-gnueabihf/libts* tslib_backup
sudo mv /usr/lib/arm-linux-gnueabihf/ts tslib_backup
sudo mv /usr/local/lib/libts* /usr/local/lib/ts /usr/lib/arm-linux-gnueabihf
(cd /usr/lib/arm-linux-gnueabihf && sudo ln -s /usr/lib/arm-linux-gnueabihf/

After uncommenting module_raw input in /etc/ts.conf and setting a few environment variables

export TSLIB_FBDEVICE=/dev/fb0
export TSLIB_TSDEVICE=/dev/input/by-id/`ls /dev/input/by-id/ | grep "eGalax"`
export TSLIB_CONFFILE=/etc/ts.conf
export TSLIB_CALIBFILE=/etc/pointercal
export TSLIB_PLUGINDIR=/usr/lib/arm-linux-gnueabihf/ts

the touchscreen can be calibrated using ts_calibrate and tested with ts_test. It might be useful to add those environment variables to ~/ as well.