1

There are a few tutorials on the net, which explain how to compile Qt5 for the Raspberry Pi. Unfortunately all of them are a bit out of date. Usually one gets 'undefined references' for some GLIBC functions. This question and answer explains how to create an up-to-date (March 2015) gcc cross compiler: How can I create a modern cross compile toolchain for the Raspberry Pi 1?

And this question and answer explains what has to be done to prepare Raspbian itself to be used by this compiler: How do I prepare a Raspberry Pi with Raspbian so I can cross compile Qt5 programs from a Linux host?

But how is the Qt5 itself compiled?

Community
  • 1
  • 1
Greenflow
  • 3,935
  • 2
  • 17
  • 28

1 Answers1

1

To create a Qt5 for the Raspberry Pi several steps are necessary:

Get the Qt5 sources from git. To checkout Qt5:

git clone http://code.qt.io/cgit/qt/qt5.git

or

git clone http://code.qt.io/qt/qt5.git

The repository might change from time to time. The qt project is still evolving.

Above command in done on the Linux host. To get the dev branch cd to qt5 and:

git checkout dev

followed by

./initRepository

This will take quite some time. In this time the Raspberry Pi root folder can be mounted. It is possible to use a card reader and mount the SD card. A much better solution is to use either nfs, samba, sshfs to mount a life Raspberry Pi. This way minor bugs, e.g. missing dev packages, are easily fixed 'on the fly'.

I use sshfs:

sshfs pi@raspberrypi:/ /home/me/rasp

If this mount is successful, The root file system of the Raspberry Pi is accessible under /home/me/rasp.

As soon as the Qt5 is checked out, the following changes must be made: In qt5/qtbase/mkspecs the file linux-arm-gnueabi-g++ must be edited (or copied and edited)

MAKEFILE_GENERATOR      = UNIX
CONFIG                 += incremental

QMAKE_INCREMENTAL_STYLE = sublib

include(../common/linux.conf)
include(../common/gcc-base-unix.conf)
include(../common/g++-unix.conf)

# modifications to g++.conf
QMAKE_CC                = <path to>/arm-linux-gnueabihf-gcc
QMAKE_CXX               = <path to>/arm-linux-gnueabihf-g++
QMAKE_LINK              = <path to>/arm-linux-gnueabihf-g++
QMAKE_LINK_SHLIB        = <path to>/arm-linux-gnueabihf-g++

# modifications to linux.conf
QMAKE_AR                = <path to>/arm-linux-gnueabihf-ar cqs
QMAKE_OBJCOPY           = <path to>/arm-linux-gnueabihf-objcopy
QMAKE_NM                = <path to>/arm-linux-gnueabihf-nm -P
QMAKE_STRIP             = <path to>/arm-linux-gnueabihf-strip


QMAKE_INCDIR_EGL        = $$[QT_SYSROOT]/opt/vc/include/EGL/
QMAKE_INCDIR_OPENGL_ES2 = $$[QT_SYSROOT]/opt/vc/include/GLES2/
QMAKE_INCDIR_OPENVG     = $$[QT_SYSROOT]/opt/vc/include/VG/  

QMAKE_LIBDIR_EGL        = $$[QT_SYSROOT]/opt/vc/lib/
QMAKE_LIBDIR_OPENGL_ES2 = $$[QT_SYSROOT]/opt/vc/lib/
QMAKE_LIBDIR_OPENVG     = $$[QT_SYSROOT]/opt/vc/lib/

QMAKE_LIBS_EGL          = -lEGL -lGLESv2                       
QMAKE_LIBS_OPENVG       = -lOpenVG -lEGL -lGLESv2         
QMAKE_LIBS_OPENGL_ES2   = -lEGL -lGLESv2

LIBS  += -L$$[QT_SYSROOT]/opt/vc/lib -lvcos -lbcm_host -lvchiq_arm 
LIBS  += -lEGL -lGLESv2 

INCLUDEPATH  += $$[QT_SYSROOT]/opt/vc/include 
INCLUDEPATH  += $$[QT_SYSROOT]/opt/vc/include/interface/vcos 

INCLUDEPATH  += $$[QT_SYSROOT]/opt/vc/include/interface/vcos/pthreads 
INCLUDEPATH  += $$[QT_SYSROOT]/opt/vc/include/interface/vmcs_host/linux

<path to> has to be replaced with the cross compiler, which was created according to: How can I create a modern cross compile toolchain for the Raspberry Pi 1?

Next step is to configure Qt5:

   ./configure -opengl es2 -device linux-rasp-pi-g++ -device-option CROSS_COMPILE=<path to>/arm-linux-gnueabihf- -xplatform linux-arm-gnueabi-g++ -sysroot /home/me/rasp -opensource -confirm-license -optimized-qmake  -release -make libs -prefix /usr/local/qt5pi -v -libinput -linuxfb -directfb -xcb  -fontconfig -ts
   lib -evdev -iconv -xinput2 -xkbcommon-evdev -eglfs -icu -qt-pcre -lpthread  -system-sqlite -no-sql-sqlite2 -gstreamer 1.0 -reduce-exports

Special attention need the following parameters:

  1. -xplatform linux-arm-gnueabi-g++ This is the mkspec. Change name accordingly, if linux-arm-gnueabi-g++ was not edited, but a new mkspec was created.

  2. -device-option CROSS_COMPILE=<path to>/arm-linux-gnueabihf- Not sure, if this is necessary. Found it in some tutorials. Everything worked fine without this option. Adjust <path to> to cross compiler just as in the mkspec.

  3. -sysroot /home/me/rasp Very important. The mount point where the Raspberry Pi is mounted.

  4. -prefix /usr/local/qt5pi Where the Qt5 is to be installed on the RPi

Now all there is to do is the usual: make/make install. The command builds Qt5 and installs it in /usr/qt5pi on the Raspberry Pi. Make sure proper write permissions exist for this location.

One more thing:

qtwayland/src/hardwareintegration/client/brcm-egl/qwaylandbrcmeglintegration.h

contained a bug when I compiled my qt5. A quick fix is to edit this file:

#include <QtWaylandClient/private/qwaylandclientbufferintegration_p.h>

#include <wayland-client.h> <--- add this below the #include above.

One last thing: This qt5 is NOT suitable to be used from within the Raspberry Pi itself. When programs are created, the RPi must be mounted and the compilation must be done under the same host with the same cross compiler on which the Qt5 was compiled.

Another last thing: The RPi does not support xcb. So X11 forwarding is not possible.

EDIT: I have been told this is not true. No, it isn't. However, what is true, the RPi does not support xcb/X11 for programs, which use OpenGL. So no qtquick 2 programs: http://lists.qt-project.org/pipermail/qtonpi/2012-October/001087.html

Nothing to be done about this at the moment, its graphics driver simply don't support it. Wayland support is limited. Best platform to be used is eglfs.

Community
  • 1
  • 1
Greenflow
  • 3,935
  • 2
  • 17
  • 28
  • The guide is almost complete, but it contains wrong information here and there. – peppe May 12 '15 at 17:00
  • There's absolutely no need to modify the mkspecs. The ones shipped with 5.3+ are just fine. Just be sure to pass the right compiler paths to `-device-option`. – peppe May 12 '15 at 17:01
  • It might be overkill to compile ALL of Qt, it's also possible to just compile the modules that one needs. – peppe May 12 '15 at 17:04
  • X11 works on RPi, so why saying it doesn't? Note how your configure command line asks for XCB support. – peppe May 12 '15 at 17:05
  • Your sshfs trick (lacking a proper sysroot) is neat, but 1) it's going to slow down the compilation *a lot*. You also need dummy ciphers to avoid overload the RPi's CPU. Plus, add the limited network bandwidth over it. 2) requires `transform_symlinks` or any absolute symlink on the RPi is going to point at non existing files on your host. – peppe May 12 '15 at 17:07
  • @pepe, this is what worked for me. And the mkspecs are not fine for the Raspberry Pi. As you can see, I added all kinds of LIBS and QMAKE variables to the mkspec. I also added the correct -device-option... did not work. My compiler was not found without the hack in this mkspec. I don't say, above tutorial is perfect. Usually there is more than one possible solution. This is more or less the result of a few days trial and at the moment I don't muss anything. – Greenflow May 12 '15 at 17:40
  • **X11 works on RPi, so why saying it doesn't?** Yes and no. You are right I have to reword this. X11 works on RPi, but is for many use cases absolutely worthless. It does not work for program, which use OpenGL: http://lists.qt-project.org/pipermail/qtonpi/2012-October/001087.html This means: No qtquick 2 on RPi using X11. – Greenflow May 12 '15 at 17:50
  • **transform_symlinks** I mentioned that in the previous part of the tutorial: http://stackoverflow.com/questions/30120871/how-do-i-prepare-a-raspberry-pi-with-raspian-so-i-can-cross-compile-qt5-programs?lq=1 Also: Probably other ways to handly this, but I am using my Qt5 on RPi for quite a while and don't see any drawbacks, yet. – Greenflow May 12 '15 at 17:54
  • The 'sshfs' slow... Yes and no... I still see people compiling qt5 on their RPi since they don't know how to setup a cross compile environment. Compared to them, the sshsf method is lightning fast. My qt5 was compiled in 6hrs. I read about 38hrs when compiled natively on an overclocked RPi. – Greenflow May 12 '15 at 17:57
  • Btw... such a tutorial should be a work in progress. If you would like to improve it.... :-) Btw2... do you think nfs or samba is faster than sshfs? As I wrote, in theory you can just mount the SD card, but I prefer to have my RPi 'life', e.g. to quick fix a path or missing package. – Greenflow May 12 '15 at 18:08