Native Build of Qt 5.4.1 on a Raspberry Pi
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.
Preparation
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 ls
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_SWAPSIZE=100 # 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 dependencies
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.
Compilation
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
Installation
sudo make install
For using the installed version of Qt, it is convenient to have a setup file, e.g. ~/setup_qt.sh, 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 export QT_QPA_EGLFS_HIDECURSOR=1 # enables tslib plugin for touch screen export QT_QPA_GENERIC_PLUGINS=Tslib # disables evdev mouse input (to avoid getting duplicated input from tslib AND evdev) export QT_QPA_EGLFS_DISABLE_INPUT=1 # set physical display dimensions for proper font sizes etc. # Qt should print a warning if this is necessary export QT_QPA_EGLFS_PHYSICAL_WIDTH=154 export QT_QPA_EGLFS_PHYSICAL_HEIGHT=86
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 # CONF_SWAPSIZE=100 # 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://github.com/kergoth/tslib.git cd tslib ./autogen.sh ./configure 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/libts-0.0.so.0 libts-1.0.so.0)
Now uncomment module_raw input in /etc/ts.conf and set a few environment variables:
export TSLIB_FBDEVICE=/dev/fb0 export TSLIB_CONSOLEDEVICE=none 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 ~/setup_qt.sh as well.