Qt5 on raspberry pi
This is documentation of my attempt to cross-compile Qt5 for raspberry pi. I followed these (link1, link2) two links but neither worked straight-up for me without some tweaks. I am running Ubuntu 12.04.3 LTS 64-bit as the host compiler platform. My Ubuntu 12 is running inside a VMWare Player virtual machine on a 64 bit, 6 core, AMD, Windows 7 host. My steps below mainly follow (link2) but with some minor tweaks and deviations.
This work was done on 22 December 2013. I found that bugs and changes had crept into the Qt builds that required the changes from the previous instructions noted. So if you attempt this its likely my instructions will also be out-dated soon.
Note: rpi = raspberry pi
End Points
After the installation, the following directories will have been created:
host
/usr/local/qt5pi — this contains binaries executable on the host such as the qmake executable and other Qt tools necessary to cross compile a Qt application.
~/opt/ — this contains the cross compiler and compiler tools and the Qt5 source code.
~/opt/raspberry.img — this contains the file system image for the target pi SD FLASH card. This image can be modified by mounting it and writing files to the mounted image. The SD FLASH card should be a copy of this image made at a point in time.
/mnt/rasp-pi-rootfs — this is the mounted target file system image.
/mnt/rasp-pi-rootfs/usr/local/qt5pi/include –the host compiler will look here to find the Qt include files.
target
/usr/local/qt5pi — this contains the Qt5 libraries needed at run time on the target pi. This directory is created on the mounted raspberry.img and then copied to the SD card.
Starting Point
Install Ubuntu and Prerequisites
Starting with a clean Ubuntu 12.04 install, which by default includes Qt 4 libraries (but not QtCreator) (we will end up with both a Qt 4 and Qt 5 native library install as well as a rpi Qt5 library). Using the Update Manager GUI tool, install all recommended updates.
Install g++
1 |
david@ubuntu:~$ sudo apt-get install g++ |
Install the openGL library.
1 |
apt-get install libgl1-mesa-dev |
Install git
1 |
david@ubuntu:~/opt$ sudo apt-get install git |
Install ia32-libs to use the 32-bit cross compiler and other tools:
1 |
david@ubuntu:~/opt$ sudo apt-get install ia32-libs |
Install Qt 5 Native SDK
Install Qt 5.2.0 for Linux 64-bit (423 MB). This provides the QtCreator IDE which will be used to write the applications to be run on the raspberry pi (and the option of developing native Linux apps for the host machine). Look for the download packages include Qt 5.2.0 libraries and Qt Creator 3.0.0 (http://qt-project.org/downloads).
Run the installer as sudo/root to provide permission for writing to the /usr/local directory.
Install in this path: /usr/local/Qt5.2.0 . After the install completed, change the owner back to the normal user for user specific configuration files:
1 2 3 |
david@ubuntu:~$ cd ~/.config david@ubuntu:~/.config$ sudo chgrp -R david QtProject david@ubuntu:~/.config$ sudo chown -R david QtProject |
Configure QtCreator for Native Building
Add to your default path the path to qtcreator, which should be: /usr/local/Qt5.2.0/Tools/QtCreator/bin/
Now run QtCreator and select the native g++ compiler. Go to Tools/Options/Compilers. Add a new manual compiler, and name it “GCC Native”. Browse to /usr/bin/g++. Click OK to save changes.
Now you should be able to create and run a native hello world program.
Download Raspbian
First start a working directory ‘~/opt’ as shown below and then get the lastest Raspbian Raw Image download such as 2013-09-25-wheezy-raspbian.zip from here: http://www.raspberrypi.org/downloads. Modify the code below so that the raspbian version matches the latest:
1 2 3 4 5 |
david@ubuntu:~$ mkdir ~/opt david@ubuntu:~$ cd ~/opt david@ubuntu:~/opt$ wget http://downloads.raspberrypi.org/raspbian_latest -O raspbian_latest.zip david@ubuntu:~/opt$ unzip raspbian_latest.zip david@ubuntu:~/opt$ mv 2013-09-25-wheezy-raspbian.img raspbian.img |
We will mount this image and keep this around on the host so that when we build applications for the target, we can link to the run-time libs that are compiled for and executed on the target. We will compile Qt5 libraries for the rpi target and copy them to this image. Eventually, this local host image can be copied to the SD card that will be used to boot the rpi.
1 |
david@ubuntu:~/opt$ sudo mount -o loop,offset=62914560 raspbian.img /mnt/rasp-pi-rootfs |
Download Source and Build Qt5 for Raspberry Pi ARM
Download the Qt5 git source code repository.
1 2 |
david@ubuntu:~$ cd ~/opt david@ubuntu:~/opt$ git clone git://gitorious.org/qt/qt5.git |
now initialize the repo, this takes a while.
1 2 |
david@ubuntu:~/opt$ cd qt5 david@ubuntu:~/opt/qt5$ ./init-repository |
This build was on the “stable” branch and this was the latest commit:
1 2 3 4 5 6 7 8 |
commit a250914fecb288f82db6a7b53e70d433898eb2f4 Author: Qt Submodule Update Bot <qt_submodule_update_bot@ovi.com> Date: Fri Dec 20 03:33:43 2013 +0200 Updated submodules. Change-Id: Iec0c8697aa573d7bdec000ab2e6fb0729c0793bc Reviewed-by: Jani Heikkinen <jani.heikkinen@digia.com> |
Get the cross-compiler, tools, and install a patch:
1 2 3 4 5 |
david@ubuntu:~/opt$ wget http://swap.tsmt.eu/gcc-4.7-linaro-rpi-gnueabihf.tbz david@ubuntu:~/opt$ tar xvf gcc-4.7-linaro-rpi-gnueabihf.tbz david@ubuntu:~/opt$ git clone git://gitorious.org/cross-compile-tools/cross-compile-tools.git david@ubuntu:~/opt$ cd ~/opt/cross-compile-tools david@ubuntu:~/opt/cross-compile-tools$ sudo ./fixQualifiedLibraryPaths /mnt/rasp-pi-rootfs/ ~/opt/gcc-4.7-linaro-rpi-gnueabihf/bin/arm-linux-gnueabihf-gcc |
Now, ready to start the compilation of Qt5 for rpi. First, configure Qt5 for rpi and specify our target install directory, then make (the -j 4 is for parallel make on four cores):
1 2 3 |
david@ubuntu:~/opt$ cd qt5 david@ubuntu:~/opt/qt5$ ./configure -opengl es2 -device linux-rasp-pi-g++ -device-option CROSS_COMPILE=~/opt/gcc-4.7-linaro-rpi-gnueabihf/bin/arm-linux-gnueabihf- -sysroot /mnt/rasp-pi-rootfs -opensource -confirm-license -optimized-qmake -reduce-exports -release -make libs -prefix /usr/local/qt5pi -no-pch david@ubuntu:~/opt/qt5$ make -j 4 |
After installing the SD card in my Dynex card reader attached to my Ubuntu host, running the df command shows there are two storage devices associated with the SD card, a boot device and primary file system. Both of these should be unmounted first:
1 2 3 4 5 6 7 8 9 10 11 12 |
david@ubuntu:~$ df -h Filesystem Size Used Avail Use% Mounted on /dev/sda1 98G 12G 82G 13% / udev 3.9G 4.0K 3.9G 1% /dev tmpfs 1.6G 808K 1.6G 1% /run none 5.0M 0 5.0M 0% /run/lock none 3.9G 152K 3.9G 1% /run/shm /dev/sdb1 56M 17M 40M 30% /media/3312-932F /dev/sdb2 3.6G 1.6G 1.9G 45% /media/b7b5ddff-ddb4-48dd-84d2-dd47bf00564a david@ubuntu:~$ umount /dev/sdb1 david@ubuntu:~$ umount /dev/sdb2 |
Now follow the instructions from link2 to copy the raspberian image to the SD card:
1 2 |
david@ubuntu:~$ sudo dd bs=1M if=raspbian.img of=/dev/sdb; david@ubuntu:~$ sync |
The sync command is important, if you don’t execute it when you pull the SD card it may not actually contain the image. The sync command took a long time to execute on my machine.