Qt wiki will be updated on October 12th 2023 starting at 11:30 AM (EEST) and the maintenance will last around 2-3 hours. During the maintenance the site will be unavailable.

Native Build of Qt5 on a Raspberry Pi

From Qt Wiki
Revision as of 14:14, 23 February 2015 by Maintenance script (talk | contribs)
Jump to navigation Jump to search

h1. Native Build of Qt 5 on a Raspberry Pi

There are many tutorials online for building Qt5 on the Raspberry Pi, but all or most of those tutorials are for using a desktop machine to cross compile the binaries for the Raspberry Pi. You will not be able to run qmake and make on the Raspberry Pi itself if you cross compile. This tutorial is meant to show you how to natively compile Qt 5 on the Raspberry Pi so that you can use qmake and make on the Raspberry Pi itself without cross compiling or relying on an external desktop.

First start off by obtaining either the latest version of Raspbian or the May 23rd version (the one I used for this tutorial). You will need at least an 8GB SD card because the space required is a bit over 4GB. Also make sure you are using the Model B or B+ with 512MB RAM. The early Raspberry Pis were shipped with 256 MB RAM which isn't sufficient and will result in an gcc error.

Turn on your Raspberry Pi and log in. Make sure you have it connected properly to the internet and that you have a power supply that is at least 1A. You may also want to overclock your Pi. I overclocked mine at 900 MHz and it took 38 hours to compile and the temperature was a steady 51 C - 54 C (with case, no heat-sinks, no fans).

Install packages needed for compiling:

sudo apt-get update<br />sudo apt-get upgrade<br />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

Then make your build directory:

mkdir <sub>/opt<br />cd</sub>/opt

Retrieve qt5 source code from git:

git clone git://gitorious.org/qt/qt5.git<code>

Retrieve git sources for other components<br />

cd qt5
./init-repository

Do not apply any patches that are available out there. They are no longer necessary with the latest Qt5. The git source should compile with a few tricks in the configure parameters without any patches.

First make sure you are in the qt5 directory.<br />

cd /opt/qt5
In order to get the configure script to build all of the Makefiles correctly you will need to tweak your
/opt/qt5/qtbase/configure script. Use your favorite text editor (vim, nano, emacs) and change/add the following code in the

/opt/qt5/qtbase/configure script (search for QT_CFLAGS_DBUS):
# flags for raspberry pi build<br /># flags for libdbus-1<br />QT_CFLAGS_DBUS=&quot;-I/usr/include/dbus-1.0/ -I/usr/lib/arm-linux-gnueabihf/dbus-1.0/include/&amp;quot;<br />QT_LIBS_DBUS=-ldbus-1
<br /># flags for Glib (X11 only)<br />QT_CFLAGS_GLIB=&quot;-I/usr/include/glib-2.0/ -I/usr/lib/arm-linux-gnueabihf/glib-2.0/include/&amp;quot;<br />QT_LIBS_GLIB=-lglib-2.0
<br />QT_CFLAGS_PULSEAUDIO=&quot;-I/usr/include/glib-2.0/ -I/usr/lib/arm-linux-gnueabihf/glib-2.0/include/&amp;quot;<br />QT_LIBS_PULSEAUDIO=&quot;-lpulse -lpulse-mainloop-glib&amp;quot;
<br /># flags for GStreamer (X11 only)<br />QT_CFLAGS_GSTREAMER=&quot;-I/usr/include/gstreamer-0.10/ -I/usr/include/glib-2.0/ -I/usr/lib/arm-linux-gnueabihf/glib-2.0/include/ -I/usr/include/libxml2/&amp;quot;<br />QT_LIBS_GSTREAMER=

Then before closing the file search for QT_CFLAGS_FONTCONFIG in the configure script. It should be below the above entries, you need to change the one in the else statement to this:
QT_CFLAGS_FONTCONFIG=-I/usr/include/freetype2/<code>
<br />If the above changes are hard to follow then you can use the following patch file:<br />
1030,1031c1030,1031
< QT_CFLAGS_DBUS=
< QT_LIBS_DBUS=

> QT_CFLAGS_DBUS="-I/usr/include/dbus-1.0/ -I/usr/lib/arm-linux-gnueabihf/dbus-1.0/include/&quot;
> QT_LIBS_DBUS=-ldbus-1
1034,1035c1034,1038
< QT_CFLAGS_GLIB=
< QT_LIBS_GLIB=

> QT_CFLAGS_GLIB="-I/usr/include/glib-2.0/ -I/usr/lib/arm-linux-gnueabihf/glib-2.0/include/&quot;
> QT_LIBS_GLIB=-lglib-2.0
>
> QT_CFLAGS_PULSEAUDIO="-I/usr/include/glib-2.0/ -I/usr/lib/arm-linux-gnueabihf/glib-2.0/include/&quot;
> QT_LIBS_PULSEAUDIO="-lpulse -lpulse-mainloop-glib&quot;
1038c1041
< QT_CFLAGS_GSTREAMER=

> QT_CFLAGS_GSTREAMER="-I/usr/include/gstreamer-0.10/ -I/usr/include/glib-2.0/ -I/usr/lib/arm-linux-gnueabihf/glib-2.0/include/ -I/usr/include/libxml2/&quot;
5123c5126
< QT_CFLAGS_FONTCONFIG=

> QT_CFLAGS_FONTCONFIG=-I/usr/include/freetype2/
<br />In order to properly run configure for Qt5 on the Raspberry Pi, you need to point the CROSS_COMPILE variable to the native compiler located at /usr/bin/g+''. The CROSS_COMPILE parameter is the path to the compiler (without the g). If you do not do this properly it will complain that it is not being cross compiled.
<br />All output is stored in the file called output in case something goes wrong. At the end of the output file it should say you can run make, if not look for errors at the end of the output.
<br />Do not be concerned with some things not building due to missing packages, there will be errors for those. If it does not mention that you can run make then check the last error, it is generally the show-stopper.<br />Run configure:<br />
./configure -v -opengl es2 -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 &> output


Check the output file to see that it is building the components you need (towards the end of the output it will have Yes next to the Qt Components that will be built) and it should say that you can now run 'make'.


Example from 'output' file:
<br />Build options:<br /> Configuration ………. accessibility accessibility-atspi-bridge alsa audio-backend c+''11 clock-gettime clock-monotonic concurrent cross_compile cups dbus egl eglfs evdev eventfd fontconfig full-config getaddrinfo getifaddrs glib gstreamer iconv icu inotify ipv6ifname large-config largefile libudev linuxfb medium-config minimal-config mremap neon nis no-pkg-config opengl opengles2 openssl pcre png precompile_header pulseaudio qpa qpa reduce_exports reduce_relocations release rpath shared small-config system-freetype system-jpeg system-png system-zlib v8 v8snapshot xcb xcb-glx xcb-render xcb-xlib xinput2 xkbcommon-qt xlib xrender<br /> Build parts ………… libs<br /> Mode ………………. release<br /> Using C''+11 ………… yes<br /> Using PCH ………….. yes<br /> Target compiler supports:<br /> iWMMXt/Neon ………. no/yes
<br />Qt modules and options:<br /> Qt D-Bus …………… yes (loading dbus-1 at runtime)<br /> Qt Concurrent ………. yes<br /> Qt GUI …………….. yes<br /> Qt Widgets …………. yes<br /> JavaScriptCore JIT .. yes (To be decided by JavaScriptCore)<br /> QML debugging ………. yes<br /> Use system proxies .. no
<br />Support enabled for:<br /> Accessibility ………. yes<br /> ALSA ………………. yes<br /> CUPS ………………. yes<br /> FontConfig …………. yes<br /> Iconv ……………… yes<br /> ICU ……………….. yes<br /> Image formats:<br /> GIF ……………… yes (plugin, using system library)<br /> JPEG …………….. yes (plugin, using system library)<br /> PNG ……………… yes (in QtGui, using system library)<br /> Glib ………………. yes<br /> GStreamer ………….. yes<br /> GTK theme ………….. no<br /> Large File …………. yes<br /> libudev ……………. yes<br /> Networking:<br /> getaddrinfo ………. yes<br /> getifaddrs ……….. yes<br /> IPv6 ifname ………. yes<br /> OpenSSL ………….. yes (loading libraries at run-time)<br /> NIS ……………….. yes<br /> OpenGL …………….. yes (OpenGL ES 2.x)<br /> OpenVG …………….. no<br /> PCRE ………………. yes (bundled copy)<br /> pkg-config …………. no<br /> PulseAudio …………. yes<br /> QPA backends:<br /> DirectFB …………. no<br /> EGLFS ……………. yes<br /> KMS ……………… no<br /> LinuxFB ………….. yes<br /> XCB ……………… yes (system library)<br /> MIT-SHM ………… yes<br /> Xcursor ………… yes (loaded at runtime)<br /> Xfixes …………. yes (loaded at runtime)<br /> Xi …………….. no<br /> Xi2 ……………. yes<br /> Xinerama ……….. yes (loaded at runtime)<br /> Xrandr …………. yes (loaded at runtime)<br /> Xrender ………… yes<br /> XKB ……………. no<br /> XShape …………. yes<br /> XSync ………….. yes<br /> XVideo …………. yes<br /> Session management .. yes<br /> SQL drivers:<br /> DB2 ……………… no<br /> InterBase ………… no<br /> MySQL ……………. yes (plugin)<br /> OCI ……………… no<br /> ODBC …………….. yes (plugin)<br /> PostgreSQL ……….. yes (plugin)<br /> SQLite 2 …………. yes (plugin)<br /> SQLite …………… yes (plugin, using bundled copy)<br /> TDS ……………… yes (plugin)<br /> udev ………………. yes<br /> xkbcommon ………….. yes (bundled copy)<br /> zlib ………………. yes (system library)
<br />NOTE: libxkbcommon 0.2.0 (or higher) not found on the system, will use<br />the bundled version from 3rd party directory.
<br />Qt is now configured for building. Just run 'make'.<br />Once everything is built, you must run 'make install'.<br />Qt will be installed into /usr/local/qt5
<br />Prior to reconfiguration, make sure you remove any leftovers from<br />the previous build.


Note, the compilation will take about two days to compile overclocked at 900 MHz. If you are logged in remotely consider using byobu or screen so that you can detach your session.


Then you need to run make as follows (check for errors in the output_make file):
make &amp;&gt; output_make<code>
<br />If that is good then run make install (check for errors in the output_make_install file):<br />
sudo make install &> output_make_install
After this you need to add some lines to your .bashrc file:
export LD_LIBRARY_PATH=/usr/local/qt5/lib/<br />export PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/usr/local/qt5/bin

You need to source your .bashrc file to set-up the above environment variables:
source</sub>/.bashrc<code>

Then run this and check that it points to /usr/local/qt5/bin/qmake<br />
which qmake Example output:
pi<code>raspberrypi <sub>/opt/qt5 $ which qmake<br />/usr/local/qt5/bin/qmake

After this you should be able to compile the sample applications and run them. Try the OpenGL Cube (I have not tested this in X windows, only from the console):
cp -r</sub>/opt/qt5/qtbase/examples/opengl/cube <sub>/<br />cd</sub>/cube<br />qmake<br />make<br />./cube