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 1: Line 1:
=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 <span class="caps">RAM</span>. The early Raspberry Pis were shipped with 256 MB <span class="caps">RAM</span> 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:<br />
Then make your build directory:<br />
Retrieve qt5 source code from git:<br />
Retrieve git sources for other components<br />
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 />
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 />
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 />
If the above changes are hard to follow then you can use the following patch file:<br />
In order to properly run configure for Qt5 on the Raspberry Pi, you need to point the <span class="caps">CROSS</span>_COMPILE variable to the native compiler located at /usr/bin/g++. The <span class="caps">CROSS</span>_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.<br /> Run configure:<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’.
Example from ‘output’ file:<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.
Then you need to run make as follows (check for errors in the output_make file):<br />
If that is good then run make install (check for errors in the output_make_install file):<br />
After this you need to add some lines to your .bashrc file:<br />
You need to source your .bashrc file to set-up the above environment variables:<br />
Then run this and check that it points to /usr/local/qt5/bin/qmake<br />
Example output:<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 />
You should now have a Raspberry Pi that can run qmake and works with OpenGL ES.

Revision as of 16:09, 14 January 2015