Native Build of Qt 5.4.1 on a Raspberry Pi: Difference between revisions

From Qt Wiki
Jump to navigation Jump to search
mNo edit summary
m (Syntax Highlights)
Line 23: Line 23:


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.
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.
 
<code lang="bash">
  sudo mkdir -p /media/usb
  sudo mkdir -p /media/usb
  # put proper device here instead of /dev/sdXX!
  # put proper device here instead of /dev/sdXX!
  sudo mount '''/dev/sdXX''' /media/usb
  sudo mount /dev/sdXX /media/usb
  sudo mkdir /media/usb/build
  sudo mkdir /media/usb/build
  sudo chown pi /media/usb/build
  sudo chown pi /media/usb/build
Line 37: Line 37:
  cd ~/opt/qt-everywhere-opensource-src-5.4.1
  cd ~/opt/qt-everywhere-opensource-src-5.4.1
  ls
  ls
 
</code>
=== Increasing available RAM for concurrent compilation ===
=== 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.
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.
 
<code lang="bash">
  # disable and remove swap file
  # disable and remove swap file
  sudo dphys-swapfile swapoff
  sudo dphys-swapfile swapoff
Line 56: Line 56:
  # check that a ~2GB swap file is active now
  # check that a ~2GB swap file is active now
  cat /proc/swaps
  cat /proc/swaps
 
</code>
== Configure and compile Qt source code ==
== Configure and compile Qt source code ==
=== Installing dependencies ===
=== Installing dependencies ===
 
<code lang="bash">
  sudo apt-get update
  sudo apt-get update
  sudo apt-get dist-upgrade
  sudo apt-get dist-upgrade
Line 73: Line 73:
   libdrm-dev flex ruby gperf bison libts-dev
   libdrm-dev flex ruby gperf bison libts-dev
  sudo apt-get clean
  sudo apt-get clean
 
</code>
In Raspbian Jessie, the package <tt>libjpeg62-dev</tt> has been removed. <tt>libjpeg62-turbo-dev</tt> can be used alternatively.
In Raspbian Jessie, the package <tt>libjpeg62-dev</tt> has been removed. <tt>libjpeg62-turbo-dev</tt> can be used alternatively.


Line 90: Line 90:
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.
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.


<code lang="bash">
  time make -j3 2>&1 | tee make.out
  time make -j3 2>&1 | tee make.out
 
</code>
== Installation and Cleanup ==
== Installation and Cleanup ==


=== Installation ===
=== Installation ===
 
<code lang="bash">
  sudo make install
  sudo make install
 
</code>
For using the installed version of Qt, it is convenient to have a setup file, e.g. <tt>~/setup_qt.sh</tt>, which can be <tt>source</tt>'d if necessary. It should contain at least the following lines for setting up path variables:
For using the installed version of Qt, it is convenient to have a setup file, e.g. <tt>~/setup_qt.sh</tt>, which can be <tt>source</tt>'d if necessary. It should contain at least the following lines for setting up path variables:
<code lang="bash">
  export LD_LIBRARY_PATH=/usr/local/qt5/lib
  export LD_LIBRARY_PATH=/usr/local/qt5/lib
  export PATH=/usr/local/qt5/bin:$PATH
  export PATH=/usr/local/qt5/bin:$PATH
 
</code>
Additionally, it can be convenient to set additional variables depending on the periphery devices connected to the Pi, i.e. a touchscreen:
Additionally, it can be convenient to set additional variables depending on the periphery devices connected to the Pi, i.e. a touchscreen:
<code lang="bash">
  # hides mouse cursor
  # hides mouse cursor
  export QT_QPA_EGLFS_HIDECURSOR=1
  export QT_QPA_EGLFS_HIDECURSOR=1
Line 113: Line 116:
  export QT_QPA_EGLFS_PHYSICAL_WIDTH=154
  export QT_QPA_EGLFS_PHYSICAL_WIDTH=154
  export QT_QPA_EGLFS_PHYSICAL_HEIGHT=86
  export QT_QPA_EGLFS_PHYSICAL_HEIGHT=86
 
</code>
=== Cleaning up ===
=== Cleaning up ===


Now some of the steps from [[#Preparation]] could be reversed:
Now some of the steps from [[#Preparation]] could be reversed:
 
<code lang="bash">
  # unbind source directory and copy source tree to SD card
  # unbind source directory and copy source tree to SD card
  sudo unmount /home/pi/opt/qt-everywhere-opensource-src-5.4.1
  sudo unmount /home/pi/opt/qt-everywhere-opensource-src-5.4.1
Line 136: Line 139:
  sudo dphys-swapfile setup
  sudo dphys-swapfile setup
  sudo dphys-swapfile swapon
  sudo dphys-swapfile swapon
 
</code>
== Additional Remarks ==
== Additional Remarks ==


Line 142: Line 145:


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 <tt>D-WAV Scientific Co., Ltd eGalax TouchScreen</tt> (from <tt>lsusb</tt>). As the library is plugin based, it could be updated without recompiling Qt.
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 <tt>D-WAV Scientific Co., Ltd eGalax TouchScreen</tt> (from <tt>lsusb</tt>). As the library is plugin based, it could be updated without recompiling Qt.
 
<code lang="bash">
  git clone git://github.com/kergoth/tslib.git
  git clone git://github.com/kergoth/tslib.git
  cd tslib
  cd tslib
Line 149: Line 152:
  make -j4
  make -j4
  sudo make install
  sudo make install
</code>


Unfortunately, the <tt>libts-0.0-0</tt> package from Raspbian Wheezy cannot be removed easily without breaking dependencies, so some 'hacking' has to be done:
Unfortunately, the <tt>libts-0.0-0</tt> package from Raspbian Wheezy cannot be removed easily without breaking dependencies, so some 'hacking' has to be done:
<code lang="bash">
  mkdir tslib_backup
  mkdir tslib_backup
  sudo mv /usr/lib/arm-linux-gnueabihf/libts* tslib_backup
  sudo mv /usr/lib/arm-linux-gnueabihf/libts* tslib_backup
Line 156: Line 161:
  sudo mv /usr/local/lib/libts* /usr/local/lib/ts /usr/lib/arm-linux-gnueabihf
  sudo mv /usr/local/lib/libts* /usr/local/lib/ts /usr/lib/arm-linux-gnueabihf
  (cd /usr/lib/arm-linux-gnueabihf && sudo ln -s libts-1.0.so.0 libts-0.0.so.0)
  (cd /usr/lib/arm-linux-gnueabihf && sudo ln -s libts-1.0.so.0 libts-0.0.so.0)
</code>


In Raspbian Jessie, the libts-0.0.0  does not seem to be required by any other package, so the previous hack can be ignored and the files installed directly to <tt>/usr</tt> and <tt>/etc</tt>:
In Raspbian Jessie, the libts-0.0.0  does not seem to be required by any other package, so the previous hack can be ignored and the files installed directly to <tt>/usr</tt> and <tt>/etc</tt>:
Line 163: Line 169:


Now uncomment <tt>module_raw input</tt> in <tt>/etc/ts.conf</tt> and set a few environment variables:
Now uncomment <tt>module_raw input</tt> in <tt>/etc/ts.conf</tt> and set a few environment variables:
<code lang="bash">
  export TSLIB_FBDEVICE=/dev/fb0
  export TSLIB_FBDEVICE=/dev/fb0
  export TSLIB_CONSOLEDEVICE=none
  export TSLIB_CONSOLEDEVICE=none
Line 169: Line 176:
  export TSLIB_CALIBFILE=/etc/pointercal
  export TSLIB_CALIBFILE=/etc/pointercal
  export TSLIB_PLUGINDIR=/usr/lib/arm-linux-gnueabihf/ts
  export TSLIB_PLUGINDIR=/usr/lib/arm-linux-gnueabihf/ts
</code>


The touchscreen can be calibrated using <tt>ts_calibrate</tt> and tested with <tt>ts_test</tt>. It might be useful to add those environment variables to <tt>~/setup_qt.sh</tt> as well.
The touchscreen can be calibrated using <tt>ts_calibrate</tt> and tested with <tt>ts_test</tt>. It might be useful to add those environment variables to <tt>~/setup_qt.sh</tt> as well.

Revision as of 07:48, 21 May 2015

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 on Raspbian Wheezy.

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

In Raspbian Jessie, the package libjpeg62-dev has been removed. libjpeg62-turbo-dev can be used alternatively.

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 Wheezy 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 libts-1.0.so.0 libts-0.0.so.0)

In Raspbian Jessie, the libts-0.0.0 does not seem to be required by any other package, so the previous hack can be ignored and the files installed directly to /usr and /etc:

...
./configure --prefix /usr --sysconfdir /etc
...

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.