Build Qt 5.2 from source (Ubuntu 13.10)
Qt 5.2 was released on the 12th of December, 2013. I wanted to give it a spin and I downloaded the source tarball to build it myself. This proved to be more difficult than expected but I managed in the end.
The biggest hurdle was to get Qt Quick (2) working. Qt Quick uses OpenGL so you need the OpenGL development headers. If these are not installed, which was the case with my new laptop, the output of the Qt configure script mentions the lack of OpenGL support. Unfortunately it took me quite some time to connect that to the fact that my build did not contain Qt Quick.
The remainder of this blog post describes how to create out-of-tree builds for Qt 5.2 and Qt Creator 3.0. I have created these builds on Ubuntu 13.10 but the information should be applicable to other flavors of Linux also.
Prerequisites
As mentioned, for Qt Quick you need to have the OpenGL development headers installed. Execute the following command to install them:
$> sudo apt-get install libgl1-mesa-dev
To have your Qt5 applications blend in with your GTK desktop, you need the GTK 2.0 development headers:
$> sudo apt-get install libgtk2.0-dev
This enables GTK theme support but even with that working, Qt5 applications use a different theme by default. To force the use of a specific style, use the -style parameter when you start the Qt5 application, for example:
$> standarddialogs -style gtk+
For Qt4 applications you can set a default style with the qtconfig-qt4 utility, but Qt5 applications ignore its settings.
Build Qt 5.2
Download the Qt 5.2 tarball and unpack it:
$> wget http://download.qt-project.org/official_releases/qt/5.2/5.2.0/single/qt-everywhere-opensource-src-5.2.0.tar.gz $> tar xvzf qt-everywhere-opensource-src-5.2.0.tar.gz
To build Qt for the local platform, execute the following commands [1]:
$> cd qt-everywhere-opensource-src-5.2.0 $> mkdir -p builds/local && cd builds/local $> export PATH=$PWD/qtbase/bin:$PATH $> ../../configure -prefix $PWD/qtbase -opensource -qt-xcb -nomake tests $> make -j 4
We use a so-called out-of-source build to make it easy to rebuild Qt without having to worry that previous build artifacts influence the new build.
With the above value of the -prefix parameter, you do not have to install Qt using the make install command.
Note the -qt-xcb parameter for the configure command. It is there to, and I quote,
[...] get rid of most xcb- dependencies. Only libxcb will still be linked dynamically, since it will be most likely be pulled in via other dependencies anyway. This should allow for binaries that are portable across most modern Linux distributions.
This is mentioned in $PWD/../qtbase/src/plugins/platforms/README.
The "-j 4" parameter to "make" specifies to run 4 jobs simultaneously. My laptop has 4 processing cores, so theoretically this could speed up compilation by a factor of 4. I did notice one drawback of using multiple jobs: when one of the jobs fails, it can be difficult to determine which compilation step failed as the messages from the failing job already have scrolled off the screen.
Build Qt Creator 3.0
Download the Qt Creator 3.0 source tarball and unpack it:
$> wget http://qt-mirror.dannhauer.de/official_releases/qtcreator/3.0/3.0.0/qt-creator-opensource-src-3.0.0.tar.gz $> tar xvzf qt-creator-opensource-src-3.0.0
To build Qt Creator, execute the following commands from the root of the extracted tarball:
$> cd qt-creator-opensource-src-3.0.0.tar.gz $> mkdir -p builds/local && cd builds/local $> qmake -r ../.. $> make -j 4
Again we create an out-of-source build.
Potentially dangerous tip
If you accidentally build Qt in its source directory, you can clean that directory using the following command:
$> find . -type f -mtime -1 -exec rm {} \;
This command deletes all files that are less than a day old. It does this silently except for:
$PWD/qtbase/src/corelib/global/qconfig.cpp
This file is read-only and you have to explicitly acknowledge that you want to delete it. It is safe to do as it the file will be regenerated during the next configure/build run. The following remarks are appropiate when you use this command:
- Be very, very careful where you execute that command. I once had it delete my new Qt build but much worse things can happen. - This command only works if the original Qt files are more than a day old, which is the case for the version we are building here.
[1] | these commands are inspired by this page of the Meego 1.2 Developer Documention |
Comments
Comments powered by Disqus