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: Difference between revisions

From Qt Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 7: Line 7:
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).
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:<br /><code>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</code>
Install packages needed for compiling:
<code>sudo apt-get update
sudo apt-get upgrade
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</code>


Then make your build directory:<br /><code>mkdir ~/opt<br />cd~/opt</code>
Then make your build directory:
<code>mkdir ~/opt
cd~/opt</code>


Retrieve qt5 source code from git:<br /><code>git clone git://gitorious.org/qt/qt5.git<code>
Retrieve qt5 source code from git:
<code>git clone git://gitorious.org/qt/qt5.git<code>


Retrieve git sources for other components<br /></code>cd qt5<br />./init-repository<code>
Retrieve git sources for other components
</code>cd qt5
./init-repository<code>


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.
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 /></code>cd ~/opt/qt5</code>
First make sure you are in the qt5 directory.
<br />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):<br /><code># flags for raspberry pi build<br /># flags for libdbus-1<br />QT_CFLAGS_DBUS="-I/usr/include/dbus-1.0/ -I/usr/lib/arm-linux-gnueabihf/dbus-1.0/include/"<br />QT_LIBS_DBUS=-ldbus-1
</code>cd ~/opt/qt5</code>
<br /># flags for Glib (X11 only)<br />QT_CFLAGS_GLIB="-I/usr/include/glib-2.0/ -I/usr/lib/arm-linux-gnueabihf/glib-2.0/include/"<br />QT_LIBS_GLIB=-lglib-2.0
<br />QT_CFLAGS_PULSEAUDIO="-I/usr/include/glib-2.0/ -I/usr/lib/arm-linux-gnueabihf/glib-2.0/include/"<br />QT_LIBS_PULSEAUDIO="-lpulse -lpulse-mainloop-glib"
<br /># flags for GStreamer (X11 only)<br />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/"<br />QT_LIBS_GSTREAMER=</code>
<br />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:<br /><code>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 /></code>1030,1031c1030,1031<br />< QT_CFLAGS_DBUS=<br />< QT_LIBS_DBUS=<br />—<br />> QT_CFLAGS_DBUS="-I/usr/include/dbus-1.0/ -I/usr/lib/arm-linux-gnueabihf/dbus-1.0/include/"<br />> QT_LIBS_DBUS=-ldbus-1<br />1034,1035c1034,1038<br />< QT_CFLAGS_GLIB=<br />< QT_LIBS_GLIB=<br />—<br />> QT_CFLAGS_GLIB="-I/usr/include/glib-2.0/ -I/usr/lib/arm-linux-gnueabihf/glib-2.0/include/"<br />> QT_LIBS_GLIB=-lglib-2.0<br />><br />> QT_CFLAGS_PULSEAUDIO="-I/usr/include/glib-2.0/ -I/usr/lib/arm-linux-gnueabihf/glib-2.0/include/"<br />> QT_LIBS_PULSEAUDIO="-lpulse -lpulse-mainloop-glib"<br />1038c1041<br />< QT_CFLAGS_GSTREAMER=<br />—<br />> 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/"<br />5123c5126<br />< QT_CFLAGS_FONTCONFIG=<br />—<br />> QT_CFLAGS_FONTCONFIG=-I/usr/include/freetype2/<code>
<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 /></code>./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 &amp;> output</code>
<br />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'.
<br />Example from 'output' file:<br /><code>…<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.</code>
<br />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.
<br />Then you need to run make as follows (check for errors in the output_make file):<br /><code>make &amp;> output_make<code>
<br />If that is good then run make install (check for errors in the output_make_install file):<br /></code>sudo make install &amp;> output_make_install</code>
<br />After this you need to add some lines to your .bashrc file:<br /><code>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</code>
<br />You need to source your .bashrc file to set-up the above environment variables:<br /><code>source~/.bashrc<code>


Then run this and check that it points to /usr/local/qt5/bin/qmake<br /></code>which qmake</code>
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):
<code># flags for raspberry pi build
# flags for libdbus-1
QT_CFLAGS_DBUS="-I/usr/include/dbus-1.0/ -I/usr/lib/arm-linux-gnueabihf/dbus-1.0/include/"
QT_LIBS_DBUS=-ldbus-1


Example output:<br /><code>pi<code>raspberrypi ~/opt/qt5 $ which qmake<br />/usr/local/qt5/bin/qmake</code>
# flags for Glib (X11 only)
<br />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):<br /><code>cp -r~/opt/qt5/qtbase/examples/opengl/cube ~/<br />cd~/cube<br />qmake<br />make<br />./cube</code>
QT_CFLAGS_GLIB="-I/usr/include/glib-2.0/ -I/usr/lib/arm-linux-gnueabihf/glib-2.0/include/"
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/"
QT_LIBS_PULSEAUDIO="-lpulse -lpulse-mainloop-glib"
 
# flags for GStreamer (X11 only)
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/"
QT_LIBS_GSTREAMER=</code>
 
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:
<code>QT_CFLAGS_FONTCONFIG=-I/usr/include/freetype2/<code>
 
If the above changes are hard to follow then you can use the following patch file:
</code>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/"
> 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/"
> 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/"
> QT_LIBS_PULSEAUDIO="-lpulse -lpulse-mainloop-glib"
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/"
5123c5126
< QT_CFLAGS_FONTCONFIG=
> QT_CFLAGS_FONTCONFIG=-I/usr/include/freetype2/<code>
 
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.
 
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.
 
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.
Run configure:
</code>./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 &amp;> output</code>
 
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:
<code>…
Build options:
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
Build parts ………… libs
Mode ………………. release
Using C''+11 ………… yes
Using PCH ………….. yes
Target compiler supports:
iWMMXt/Neon ………. no/yes
 
Qt modules and options:
Qt D-Bus …………… yes (loading dbus-1 at runtime)
Qt Concurrent ………. yes
Qt GUI …………….. yes
Qt Widgets …………. yes
JavaScriptCore JIT ….. yes (To be decided by JavaScriptCore)
QML debugging ………. yes
Use system proxies ….. no
 
Support enabled for:
Accessibility ………. yes
ALSA ………………. yes
CUPS ………………. yes
FontConfig …………. yes
Iconv ……………… yes
ICU ……………….. yes
Image formats:
GIF ……………… yes (plugin, using system library)
JPEG …………….. yes (plugin, using system library)
PNG ……………… yes (in QtGui, using system library)
Glib ………………. yes
GStreamer ………….. yes
GTK theme ………….. no
Large File …………. yes
libudev ……………. yes
Networking:
getaddrinfo ………. yes
getifaddrs ……….. yes
IPv6 ifname ………. yes
OpenSSL ………….. yes (loading libraries at run-time)
NIS ……………….. yes
OpenGL …………….. yes (OpenGL ES 2.x)
OpenVG …………….. no
PCRE ………………. yes (bundled copy)
pkg-config …………. no
PulseAudio …………. yes
QPA backends:
DirectFB …………. no
EGLFS ……………. yes
KMS ……………… no
LinuxFB ………….. yes
XCB ……………… yes (system library)
MIT-SHM ………… yes
Xcursor ………… yes (loaded at runtime)
Xfixes …………. yes (loaded at runtime)
Xi …………….. no
Xi2 ……………. yes
Xinerama ……….. yes (loaded at runtime)
Xrandr …………. yes (loaded at runtime)
Xrender ………… yes
XKB ……………. no
XShape …………. yes
XSync ………….. yes
XVideo …………. yes
Session management ….. yes
SQL drivers:
DB2 ……………… no
InterBase ………… no
MySQL ……………. yes (plugin)
OCI ……………… no
ODBC …………….. yes (plugin)
PostgreSQL ……….. yes (plugin)
SQLite 2 …………. yes (plugin)
SQLite …………… yes (plugin, using bundled copy)
TDS ……………… yes (plugin)
udev ………………. yes
xkbcommon ………….. yes (bundled copy)
zlib ………………. yes (system library)
 
NOTE: libxkbcommon 0.2.0 (or higher) not found on the system, will use
the bundled version from 3rd party directory.
 
Qt is now configured for building. Just run 'make'.
Once everything is built, you must run 'make install'.
Qt will be installed into /usr/local/qt5
 
Prior to reconfiguration, make sure you remove any leftovers from
the previous build.</code>
 
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):
<code>make &amp;> output_make<code>
 
If that is good then run make install (check for errors in the output_make_install file):
</code>sudo make install &amp;> output_make_install</code>
 
After this you need to add some lines to your .bashrc file:
<code>export LD_LIBRARY_PATH=/usr/local/qt5/lib/
export PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/usr/local/qt5/bin</code>
 
You need to source your .bashrc file to set-up the above environment variables:
<code>source~/.bashrc<code>
 
Then run this and check that it points to /usr/local/qt5/bin/qmake
</code>which qmake</code>
 
Example output:
<code>pi@raspberrypi ~/opt/qt5 $ which qmake
/usr/local/qt5/bin/qmake</code>
 
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):
<code>cp -r~/opt/qt5/qtbase/examples/opengl/cube ~/
cd~/cube
qmake
make
./cube</code>

Revision as of 12:28, 25 February 2015

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
sudo apt-get upgrade
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 ~/opt
cd~/opt

Retrieve qt5 source code from git:

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

Retrieve git sources for other components

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.

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
# flags for libdbus-1
QT_CFLAGS_DBUS="-I/usr/include/dbus-1.0/ -I/usr/lib/arm-linux-gnueabihf/dbus-1.0/include/"
QT_LIBS_DBUS=-ldbus-1

# flags for Glib (X11 only)
QT_CFLAGS_GLIB="-I/usr/include/glib-2.0/ -I/usr/lib/arm-linux-gnueabihf/glib-2.0/include/"
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/"
QT_LIBS_PULSEAUDIO="-lpulse -lpulse-mainloop-glib"

# flags for GStreamer (X11 only)
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/"
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>

If the above changes are hard to follow then you can use the following patch file:

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/" > 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/" > 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/" > QT_LIBS_PULSEAUDIO="-lpulse -lpulse-mainloop-glib" 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/" 5123c5126 < QT_CFLAGS_FONTCONFIG= —

> QT_CFLAGS_FONTCONFIG=-I/usr/include/freetype2/

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.

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.

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.
Run configure:

./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:


Build options:
 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
 Build parts ………… libs
 Mode ………………. release
 Using C''+11 ………… yes
 Using PCH ………….. yes
 Target compiler supports:
 iWMMXt/Neon ………. no/yes

Qt modules and options:
 Qt D-Bus …………… yes (loading dbus-1 at runtime)
 Qt Concurrent ………. yes
 Qt GUI …………….. yes
 Qt Widgets …………. yes
 JavaScriptCore JIT .. yes (To be decided by JavaScriptCore)
 QML debugging ………. yes
 Use system proxies .. no

Support enabled for:
 Accessibility ………. yes
 ALSA ………………. yes
 CUPS ………………. yes
 FontConfig …………. yes
 Iconv ……………… yes
 ICU ……………….. yes
 Image formats:
 GIF ……………… yes (plugin, using system library)
 JPEG …………….. yes (plugin, using system library)
 PNG ……………… yes (in QtGui, using system library)
 Glib ………………. yes
 GStreamer ………….. yes
 GTK theme ………….. no
 Large File …………. yes
 libudev ……………. yes
 Networking:
 getaddrinfo ………. yes
 getifaddrs ……….. yes
 IPv6 ifname ………. yes
 OpenSSL ………….. yes (loading libraries at run-time)
 NIS ……………….. yes
 OpenGL …………….. yes (OpenGL ES 2.x)
 OpenVG …………….. no
 PCRE ………………. yes (bundled copy)
 pkg-config …………. no
 PulseAudio …………. yes
 QPA backends:
 DirectFB …………. no
 EGLFS ……………. yes
 KMS ……………… no
 LinuxFB ………….. yes
 XCB ……………… yes (system library)
 MIT-SHM ………… yes
 Xcursor ………… yes (loaded at runtime)
 Xfixes …………. yes (loaded at runtime)
 Xi …………….. no
 Xi2 ……………. yes
 Xinerama ……….. yes (loaded at runtime)
 Xrandr …………. yes (loaded at runtime)
 Xrender ………… yes
 XKB ……………. no
 XShape …………. yes
 XSync ………….. yes
 XVideo …………. yes
 Session management .. yes
 SQL drivers:
 DB2 ……………… no
 InterBase ………… no
 MySQL ……………. yes (plugin)
 OCI ……………… no
 ODBC …………….. yes (plugin)
 PostgreSQL ……….. yes (plugin)
 SQLite 2 …………. yes (plugin)
 SQLite …………… yes (plugin, using bundled copy)
 TDS ……………… yes (plugin)
 udev ………………. yes
 xkbcommon ………….. yes (bundled copy)
 zlib ………………. yes (system library)

NOTE: libxkbcommon 0.2.0 (or higher) not found on the system, will use
the bundled version from 3rd party directory.

Qt is now configured for building. Just run 'make'.
Once everything is built, you must run 'make install'.
Qt will be installed into /usr/local/qt5

Prior to reconfiguration, make sure you remove any leftovers from
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;> output_make<code>

If that is good then run make install (check for errors in the output_make_install file):

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/
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~/.bashrc<code>

Then run this and check that it points to /usr/local/qt5/bin/qmake

which qmake

Example output:

pi@raspberrypi ~/opt/qt5 $ which qmake
/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~/opt/qt5/qtbase/examples/opengl/cube ~/
cd~/cube
qmake
make
./cube