Bring up Qt 5 on Raspberry Pi with Wayland

Ok, I’ve been waiting to do this for quite some time but never had the time to actually do it. I tried this quickly twice but without success because of many issues. Now I invested some hours and made it to the end of the journey 🙂
I therefore try to describe here the steps to make Qt 5.0.1 (the current version in the Qt git) on the new wheezy image with Wayland support.

Building the Qt Fundamental Modules

Of course the procedure is almost identical to the one used for Qt 5.0 that I described here. I only did a couple of things to speed up the process, you choose how to do it. I briefly describe here some of the steps.

  • Download the latest available wheezy image from the Raspberry Pi website: http://www.raspberrypi.org/downloads.
  • Uncompress the image and flash it to your SD card.
  • Boot the new image on your board.
  • Install some libs that we will need (I won’t compile the xcb platform plugin here, so in this case I decided not to install those xcb libs):
$ sudo apt-get install libdbus-1-dev libudev-dev libssl-dev
$ sudo apt-get install libasound2-dev
$ sudo apt-get install libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev libgstreamer-plugins-bad0.10-dev
$ sudo apt-get install libffi-dev libpixman-1-dev
$ sudo apt-get install libsqlite3-dev libicu-dev libfontconfig1-dev

libdbus-1-dev is used to get the QtDBus module compiled from qtbase, libudev-dev to get udev support, libssl-dev for OpenSSL and libasound2-dev will provide Qt what it needs for ALSA support.

GStreamer libs instead are mainly used in the qtmultimedia and qtwebkit modules. If the environment is setup correctly for gstreamer support, then the configure script will report the success.
libffi-dev libpixman-1-dev are needed to compile the qtwayland module or its dependencies. libsqlite3-dev libicu-dev and libfontconfig1-dev instead are needed only if you intend to use QtWebKit.Instead of the loopback mount of the image on your system to get a correct sysroot, I quickly scp’ed the needed binaries from my board to a newly created sysroot. In particular I copied:

/lib
/usr/lib
/usr/include
/opt

I’ll refer to the directory containing all of this as rasp_sysroot. Quick and dirty. You might also consider using rsync though.
As a final note on this I have to say that scp has the somehow pleasant collateral effect of following the symlinks in libs.

  • Clone the qt5 git repo and start building the qtbase module:
$ git clone git://gitorious.org/qt/qt5.git
$ cd qt5
$ ./init-repository
$ cd qt5/qtbase
$ ./configure -prefix your_qt_prefix -release -device linux-rasp-pi-g++ 
-make libs -device-option CROSS_COMPILE=your_toolchain_path/bin/arm-linux-gnueabihf- 
-device-option DISTRO=wheezy -sysroot your_sysroot_path -opensource 
-confirm-license -no-pch -make examples -nomake tests
$ make -jn
$ sudo make install

In my case it was done automatically by the configure script, but you might need to set the pkgconfig path before running the configuration script:

$ export PKG_CONFIG_PATH=your_sysroot_path/usr/lib/arm-linux-gnueabihf/pkgconfig
$ export PKG_CONFIG_LIBDIR=yout_sysroot_path/usr/lib/pkgconfig:your_sysroot_path/usr/lib/arm-linux-gnueabihf/pkgconfig
$ export PKG_CONFIG_SYSROOT_DIR=yout_sysroot_path

During compilation I got an error indicating that it was impossible to find the header “vchost_config.h”. I solved by editing the file in rasp_sysroot/opt/vc/include/interface/vmcs_host/vcgencmd.h:

< #include "vchost_config.h"
---
> #include "linux/vchost_config.h"

This is not very elegant maybe… anyway it is sufficient. You might add an include path in the qmake.conf or similar, but it seemed good that way 🙂

At this point qtbase should have been successfully compiled. Now at least you should compile the qtscript, qtjsbackend and the qtdeclarative module:

$ cd ..
$ cd qtscript
$ your_qt_prefix/bin/qmake
$ make -j<n>
$ sudo make install

Repeat the same for the other two modules.

Building the QtWayland Dependencies

The xkbcommon and the wayland libraries must be cross-compiled before trying to build QtWayland. To do that first setup the environment; I used this script to do it:

export RPI_SYSROOT=your_sysroot_path
export TOOLCHAIN=your_toolchain_path
export QTDIR=your_qt_sources_dir/qtbase
export PATH=$QTDIR/bin:$TOOLCHAIN/bin:$PATH
export PREFIX=your_qt_prefix
export PKG_CONFIG_PATH="$RPI_SYSROOT/usr/lib/pkgconfig:$RPI_SYSROOT/$PREFIX/lib/pkgconfig:$RPI_SYSROOT/$PREFIX/share/pkgconfig"
export PKG_CONFIG_SYSROOT_DIR="$RPI_SYSROOT"
export PKG_CONFIG_ALLOW_SYSTEM_LIBS=1
export PKG_CONFIG_ALLOW_SYSTEM_CFLAGS=1
export CPP=$TOOLCHAIN/bin/arm-linux-gnueabihf-cpp
export CC=$TOOLCHAIN/bin/arm-linux-gnueabihf-gcc
export CXX=$TOOLCHAIN/bin/arm-linux-gnueabihf-g++
export CFLAGS="--sysroot=$RPI_SYSROOT"
export CXXFLAGS="--sysroot=$RPI_SYSROOT"
export CPPFLAGS="--sysroot=$RPI_SYSROOT"
export LD=$TOOLCHAIN/bin/arm-linux-gnueabihf-ld
export LDFLAGS="--sysroot=$RPI_SYSROOT"
export AS=$TOOLCHAIN/bin/arm-linux-gnueabihf-as
export STRIP=$TOOLCHAIN/bin/arm-linux-gnueabihf-strip
export AR=$TOOLCHAIN/bin/arm-linux-gnueabihf-ar 

Start the script and download from git the xkbcommon lib:

$ source env_setup.sh
$ git clone git://people.freedesktop.org/xorg/lib/libxkbcommon.git
$ cd libxkbcommon/
$ ./autogen.sh --prefix=some_prefix --host=arm-linux-gnueabihf
$ make && make install

Copy libs and headers resulting to your_sysroot_path.
Now before compiling the wayland library the wayland scanner is needed for the generation of C code from Wayland protocols. To compile this, open a new environment for standard compilation and start compiling the wayland-scanner and place it in the PATH:

$ git clone git://anongit.freedesktop.org/wayland/wayland
$ cd wayland
$ ./autogen.sh --disable-documentation
$ make
$ cp src/wayland-scanner $QTDIR/bin 

Now get back to the cross-compilation environment and compile the wayland library itself:

$ cd wayland_dir
$ git clean -dxf
$ ./autogen.sh --host=arm-linux-gnueabihf --prefix=$RPI_SYSROOT$PREFIX --disable-scanner --disable-documentation
$ make
$ sudo make install 

Then, if necessary, copy the libraries into your sysroot.
Now let’s build QtWayland:

$ export QT_WAYLAND_GL_CONFIG=brcm_egl
$ cd your_qt_sources_dir
$ git clone http://qt.gitorious.org/qt/qtwayland
$ cd qtwayland
$ your_qt_prefix/qmake CONFIG+=wayland-compositor
$ make
$ sudo make install

At this point I have to say I had issues during the execution of the qmake binary. Unfortunately I couldn’t track down all the reasons, but it seems that libxkbcommon couldn’t be found. According to the .pro file, the qtCompileTest function is used to check if config.test/xkbcommon can be built. Appearantly, the inclusion of X11/keysym.h couldn’t be satisfied, and also it shouldn’t be needed… but although the file can be compiled, the qtwayland.pro file still was failing, so I simlply removed the checks for xkbcommon and the rest of the build procedure succeeded.

load(configure)
qtCompileTest(wayland)
#qtCompileTest(xkbcommon)
qtCompileTest(wayland_scanner)
qtCompileTest(wayland_egl)
qtCompileTest(egl)
qtCompileTest(brcm_egl)
qtCompileTest(glx)
qtCompileTest(xcomposite)

CONFIG += config_xkbcommon

load(qt_parts)

!config_wayland {
error(QtWayland requires Wayland 1.0.0 or higher)
}

#!config_xkbcommon {
error(QtWayland requires xkbcommon 0.2.0 or higher)
}

!config_wayland_scanner {
error(QtWayland requires wayland-scanner)
}

!config_wayland_egl {
message("no wayland-egl support detected, cross-toolkit compatibility disabled");

Running Applications Using the QtWayland Platform Plugin

Now copy the result of the build which should now be in your sysroot into your Pi and try to run the Wayland example compositor from QtWayland:

cd your_qt_prefix/examples/qtwayland/qml-compositor
export XDG_RUNTIME_DIR=/tmp
./qml-compositor -platform eglfs

At this point the server should be running. Now open another shell and try to run any Qt application using the wayland-brcm platform plugin:

$ cd your_app_path
$ ./your_app_bin -platform wayland-brcm &

Now you should see the window on the screen.
It is possible however that some EGL/OpenGL error occurs, like eglCreatePixmapSurface failed: 3003, global image id: 0 0, then consider increasing the memory reserved to the GPU, that is a bad_allocation error. Simply add gpu_mem=n, where n is the number of MBs to assign to the GPU in the /boot/config.txt file. Read here for more information: http://elinux.org/RPiconfig.

Building QtWebKit

For more details refer to this. It seems Qt guys have done a good work on QtWebKit. Making it work simply requires to build and run. Compile as said the qtwebkit module, then copy back the libraries to the device and load a WebView element.
The only thing that still seems to be missing is the 16bit color depth support: if you try tu run you might see a mess on the scren, that is because the QtWebProcess is writing 24bit image on 16bit mode. More details on this here.
Anyway, it seems now it is sufficient to set the framebuffer to 24bits to make it work:

$ fbset -depth 24 

No need to modify the eglfs plugin anymore. The EGL configuration seems to correctly reflect the framebuffer color depth.

Building QtMultimedia

QtMultimedia is the module responsible for the multimedia content handling. For Linux, it is based on gstreamer, which is available, ad already said, for Raspberry Pi. Anyway, gstreamer relies on plugins to decode/render multimedia content, but most of those are clearly not hardware accelerated, which makes it nearly useless on an embedded platform for video playback.

Anyway, there is a plugin that is supposed to use the RPi accelerated OpenMAX libraries, gst-omx. I have to say I still have never seen it working well, so I’m not sure whether this is working or not on Pi. It is an interesting subject, but I don’t know if or when I’ll get my hands on that.
I tried the QtMultimedia module a couple of times though, and I could play a couple of videos, but the result was clearly useless. Something like this should play the video (no audio):

import QtQuick 2.0
import QtMultimedia 5.0

Rectangle {
   width:  1920
   height: 1080

   color: "black"
 
   MediaPlayer {
      id: player
      source: "file://..."
      autoPlay: true
   }

   VideoOutput {
      id: videoOutput
      source: player
      anchors.fill: parent
   }
}

Bye!

55 thoughts on “Bring up Qt 5 on Raspberry Pi with Wayland”

  1. Does QtWayland work with Raspbian Jessie?
    I just tried to native compile the QtWayland module and got the following error from qmake CONFIG += wayland-compositor:

    Project WARNING: No xkbcommon 0.2.0 or higher found, disabling support for it

    If I comment out the check for xkbcommon like you showed, the module builds without error but when making the qml compositor example I get this error:

    Project ERROR : Unknown Modules(s) in QT: Compositor

  2. Should I compile Qt like your way. There are qt5 packages in archLinuxArm. If I use these packages, can I use your library

  3. When i launch opengl apps it launches but unable display or render on screen, Then it seems that opengl application will not have support in qtwayland??? or Im missing any configuration?

  4. Edit qtbase/mkspecs/devices/linux-rasp-pi-g++/qeglfshooks_pi.cpp and cast the 9th argument to DISPMANX_TRANSFORM_T on line 133.

    Also comment out the declaration of vc_dispmanx_element_change_attributes couple of lines above.

  5. Hi I followed above steps, and now Im able launch all application using wayland-brcm platform, But im when i launch opengl examples like hellowindow with wayland-brcm platform , the opengl app hellowindow is not launching as expected like when we launch with eglfs platform.

    ./qmlcompositor -platform eglfs& (its working fine)

    ./wiggly -platform wayland-brcm (working fine)

    opengl/hellowindow/hellowindow -platform wayland-brcm (not working)

    nothing coming

    stoping at ..
    Brcm-EGL

    so whats the reason for this ? But here its working fine http://www.youtube.com/watch?v=HItv4HX5r3k&list=UUznZH9PHUe2L4WxvPAXPPSA&index=3

  6. ็Hi guy. Someone can help me? (when i compile qt5 i got this)

    /mkspecs/devices/linux-rasp-pi-g++/qeglfshooks_pi.cpp:195:10: warning: unused parameter ‘window’ [-Wunused-parameter]
    make[4]: *** [.obj/release-shared/qeglfshooks_pi.o] Error 1
    make[4]: Leaving directory `/home/host/raspberry/qt-everywhere-opensource-src-5.1.1/qtbase/src/plugins/platforms/eglfs'
    make[3]: *** [sub-eglfs-make_first] Error 2
    make[3]: Leaving directory `/home/host/raspberry/qt-everywhere-opensource-src-5.1.1/qtbase/src/plugins/platforms'
    make[2]: *** [sub-platforms-make_first] Error 2
    make[2]: Leaving directory `/home/host/raspberry/qt-everywhere-opensource-src-5.1.1/qtbase/src/plugins'
    make[1]: *** [sub-plugins-make_first] Error 2
    make[1]: Leaving directory `/home/host/raspberry/qt-everywhere-opensource-src-5.1.1/qtbase/src'
    make: *** [sub-src-make_first] Error 2

    Thx you.

  7. I think qwayland-wayland.h may be generated by qtwaylandscanner, but the lack of documentation makes it hard to tell. I can't get qtwaylandscanner to compile against Qt 5.0.2, so I can't get past this step.

  8. I used also the "file" command and the response is:
    ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.26, BuildID[sha1]=0x0e7dd2b5a3dc8286c1b5af7756e77812b7c13e7e, not stripped

  9. Hello Luca,
    I have cross-compiled Qt5 following your instructions.

    Unfortunately I have an error when I try to run the compiled program on the raspberry:

    "Illegal Instruction"

    I cannot fix it. Do you have any idea to solve it?

    Thank you

  10. On the contrary, for Raspberry Pi, Qt5 seems to be the most mature. I don't even know what is supported for Qt4 on Pi. Read the wiki of the Qt project: http://qt-project.org/wiki/RaspberryPi. Last paragraph. Why using something that has been outdated for more than 6 months?

    As for gdb, you might start from the manual in the toolchain… seems pretty reasonable… If you're using the linaro toolchain look here: https://github.com/raspberrypi/tools/tree/master/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/share/doc/gcc-linaro-arm-linux-gnueabihf-raspbian/html/gdb.

  11. Hello Luca, hello everyone

    just a question from a beginner in Qt for remote cross-compiling:
    I would like to have Qt4 on raspberry and being able to remote cross-compile and remote debugging from a host pc; just exactly what you describe here, but simply from Qt4 and not Qt5 (since I don't need it: and it seems to me that Qt4 is much more mature for raspberry than Qt5).

    I successfully managed to install Qt4 + QtDesigner locally on Raspberry (very easy), but now I wonder how to set up the QtDesigner and the cross-compiler and gdb on the host PC… I never did it and I don't know where to start; would you have any recommendation?

    any tip is much appreciated!
    thanks a lot
    Giovanni

  12. I have bypass the Wayland version problem but i have another problem "no wayland-egl support detected, cross-toolkit compatibility disabled" and when I simply removed the checks of wayland_egl in .pro file and I try to do the "make" I have some fatal error like "fatal error: qwayland-windowmanager.h: No such file or directory" or "fatal error: qwayland-wayland.h":No such file or directory" (I haven't found these headers on my computer). Do you have any idea ?

  13. I tried different prefix like /usr/local/, /mnt/rasp-pi-rootfs/usr/local, /mnt/rasp-pi-rootfs/usr/local/qt5pi (I use a mounted image of raspbian)etc but nothing works… any help about that ?
    Thank you in advance.

  14. Hello, I have the same problem as the previous person: "Project ERROR: Wayland QtWayland Requires 1.0.3 or higher" and you answered to place headers and libs in the correct position. I would like to know what is the good position for libs and headers (can you tell me the path plz) ?

    Thank you in advance.

  15. To share the image you could use a server as uploaded.to, rapidgator.com, etc. You can upload the compressed image in parts in rar and it should be fine.

    I will continue looking for ways to run my compilation.

  16. You're right… I forgot to specify to clone the qtwayland git. I added that.

    It seems that for some reason qmake is not finding the wayland lib. Place headers and libs in the correct position. Try to compile the test in config.test to have more information.

    If I could find a way to transfer, I could provide my image, but still I don't know how.

  17. Hello again, after trying to build QT5 I have been many advances. Now I'm building qtwayland but I have a problem I have not managed to solve. In this step (Building the QtWayland Dependencies) I am unable to build "qtwayland". I managed to build wayland but could not build "qtwayland" that the module was not QT5 sources so I had to download it from "http://qt.gitorious.org/qt/qtwayland&quot;. Despite this drawback had supposedly solved, when I want to build qtwayland gives me the error "Project ERROR: Wayland QtWayland Requires 1.0.3 or higher".

    I have rebuilt a lot of times with different "PREFIX" and other changes but the error is always the same.
    I do not know what else to do and so I turn to you again.
    Hopefully I can help.

    THANKS!!

  18. I had already built qmake and then I started with the other modules. I have undone the modules to compile in order but in VirtualBox (Debian 6.6 Squeeze i386) still does not work. On another computer with Ubuntu 12.10 x64, so far I have managed to compile everything "qtdeclarative" and continue with the remaining modules and I'll tell you as I have found everything.

    Thank you.

  19. The order for build modules is : qtimageformats qtsvg qtjsbackend qtscript qtxmlpatterns qtdeclarative qtsensors qt3d qtgraphicaleffects.

    I've been following this guide "https://gitorious.org/raspberry-qt/raspberry-qt/blobs/master/README.txt&quot;. This guide appears to me to compile the modules "qtsensors" and "qt3d" which are not likely to compile and I lower them in some branch of gitorius but I saw that there are important not named.

    I have not mentioned that my sysroot not the complete picture of my SD card but I only copied the required libraries as mentioned in your guide Luca Carlon "Bring up on Raspberry Pi Qt 5.0.1 with Wayland."

    Now I'm trying to compile QT5 in "ubuntu 12.10 x64" riding the full image of my SD card.

    The truth is that I've read so much about how to compile QT5 but I must be doing something wrong that I always fail. Many people say that it works and I follow the same guidelines that they do not want to run.

    I will not change the language used raspbian when configured in the RPI?? I've used "es_CL.UTF-8" and saw a guide that said to use the version "en_US.UTF-8".

    Well I hope to complete this great task so we can continue developing some applications I need.

    Thank you.

  20. Hello again, I have finally made ​​progress in the compilation of QT5, now I just need to build the module "qtdeclarative" but throws me the following error:

    Project ERROR: Unknown module (s) in QT_PRIVATE: v8
    make [1]: *** [sub-qml-make_first-ordered] Error 3
    make [1]: Leaving directory `/ home/usuario/opt/qt5/qtdeclarative/src '
    make: *** [sub-src-make_first] Error 2

    This has already happened to me before and I had not managed to solve and I now it has happened again but still can not find the solution.

    ¿Someone could help me? Please I need so much this.

    Thanks a lot.

  21. I do not know what I'm doing wrong but I've never managed to compile QT5. I followed the guidelines to the letter but I always fail and I have never managed to finish a compilation of QT5. I search and search but still can not get good results.

    I've also tried to "http://qt-project.org/wiki/RaspberryPi_Beginners_guide&quot; and other guidelines and also the script "bakeqtpi.bash" but I always fail.

    The truth is I do not know what is wrong with what I'm doing.

    I will continue testing other configurations and hope to have good results.

    My system is a "Debian Squeeze i386 6.0.7" with Virtual Box.

    Thank you again.

  22. Meanwhile, latest RPi image (2013-02-09-wheezy-raspbian), latest Qt5 git sources (5.0.2), installed a couple of dependency packages and got the thing running – great work, I will keep checking the code and if time allows, clean the 380+ warnings that are popping up – but for now I'll head on to QML goodness!

    I also tried the gstreamer1.0 + gst-omx approach but it still didn't work for me so far, some developments here:

    http://www.raspberrypi.org/phpBB3/viewtopic.php?t=34250&p=293243

    These guys built debian packages and an alternative repo for Raspbian, might worth checking out with time.

  23. Have you followed this guide >> http://qt-project.org/wiki/RaspberryPi_Beginners_guide

    Also, if XCB isn't a dead necessity for you (i.e. working with framebuffer alone, no desktop) – check out the bakeqtpi.bash script

    This is the configure line I'm using to cross compile Qt5 for the RPi:

    CONFIGURE_OPTIONS="-opengl es2 -device linux-rasp-pi-g++ -device-option CROSS_COMPILE=$CROSSCOMPILER/bin/arm-linux-gnueabihf- -sysroot $ROOTFS -opensource -conf
    irm-license -optimized-qmake -release -make libs -prefix $QT5PIPREFIX -no-pch -nomake examples -nomake tests"

  24. Hey guys, I've been trying to compile again set QT5 but I get an error "eglconvenience/qeglconvenience_p.h: 49:21: fatal error: EGL/egl.h: No such file or directory".

    I'm trying to compile QT5 and the module XCB and do not know if the reason for my error.

    I'll keep trying and hopefully achieve first, compile QT5 I need both.

    Greetings.

  25. I can also confirm that building the latest Qt5 (5.0.2) from git for the RPi is successful and the modules as well – make sure you are building the modules in the right order, because it matters, some depend on others for proper building.

  26. Please could you tell me the basic steps and distros versions you used to install QT5 in raspberry??

    I'm using VirtualBox and Debian Squeeze 6.0.6-i386.

    Thanks

  27. Yes, I build and install the qtscript and qtjsbackend but qtdeclarative I can't build… why ???

  28. Hi Guys, now I still follow trying compile qt5 and not have good news. I try so much guides and I not have good compilation.

    I follow this guide but I have not good end.

    Now I have the following problem:

    Project ERROR: Unknown module(s) in QT_PRIVATE: v8
    make[1]: *** [sub-qml-make_first-ordered] Error 3
    make[1]: se sale del directorio `/home/myuser/opt/qt5/qtdeclarative/src'
    make: *** [sub-src-make_first] Error 2

    In my dir prefix install qt5 /usr/local/qt5/mkspecs/modules/ i have "qt_lib_v8.pri" but not "qt_v8.pri"

    In my distro I have not the library "qt_v8.pri".

    I have looked at many similar errors but none gives me a solution and do not know where to look further.
    Someone could write more retail installation QT5 for raspberry??
    Someone could upload an ISO image of your full QT5 final distro installed??
    I do not know where to keep trying as I've never succeeded in installing (following many guides) QT5.

    Please I need to build a QTPlayer with omxplayer and webkit for a multimedia project.

    Thank a lots.

  29. Thanks for the reference, I was wondering if it might be something like that – because this time around, Qt is on 5.0.2, Raspbian is on 2013-02-09 Wheezy and maybe that would all be related to the build issues…

    While attempting to create a Qt5 media player for the Pi, I think there are 2 main roads at the moment: Qt5 with omxplayer libraries, from your findings -or- Qt5 > gst-omx > GStreamer – and so far I believe that while the gst-omx approach would be the cleanest, it isn't quite at the same performance level as libomxplayer…

    Anyways, I would still like to see your approach working and improve upon it, so I will be working with it for now! Thank you for your support!

  30. Hi, yes QtMultimedia on Pi isn't quite there yet, and gst-omx would be showing some promise but recently it migrated to gstreamer1.0… and raspbian stable at least still rolls with 0.10 so gst-omx would require gstreamer 1.0 as well – that is why your other alternative – omxplayer libs – seemed more appealing. I've been trying to build your git sources but so far I've hit a few build errors – undefined references with OMXReader.o and OMXAudioCodec as well, on av_get_audio_channels I think.

Leave a Reply

Your email address will not be published. Required fields are marked *