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++

Install the openGL library.

Install git

Install ia32-libs to use the 32-bit cross compiler and other tools:

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:

 

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:

 

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.

 

Download Source and Build Qt5 for Raspberry Pi ARM

Download the Qt5 git source code repository.

 

now initialize the repo, this takes a while.

 

This build was on the “stable” branch and this was the latest commit:

 

Get the cross-compiler,  tools, and install a patch:

 

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):

 

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:

 

Now follow the instructions from link2 to copy the raspberian image to the SD card:

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.