I have configured and built my own release version of Qt for gcc 64bit on linux, and with static linkage.
The process goes like this (from the README file deliverd with qt):
- Download qt-everywhere-* source tarball
- Extract qt into a folder "qtdir"
- Make a new dir "shadow" beside "qtdir" and go into it
- Run "qtdir"/qtbase/configure -prefix "qtdir"/qtbase
- Run make
- Wait for qt build to complete. Takes a suprisingly short time.
- Build my project with the resulting qmake
When I use the resulting qmake on my previously working project, it quits with the message
"Project ERROR: Unknown module(s) in QT: multimedia multimediawidgets
My project file contains the following:
QT += core gui xml network widgets multimedia multimediawidgets svg
My question is thus, what is the correct way to compile qt statically while including all desired modules in the build?
Thanks!
It turns out that building qt statically was more difficult than I first expected (hoped?)
In this answer I will outline my journey to finally have a complete working statically linked qt that will compile properly with my project on Qt5/64bit/Linux.
First a list of hints that were crucial for my success:
Make sure to have the 3rd party dependencies that qt require installed. The easiest way to arrange for this is to install the development packages using the package management in your Linux distribution. The more hardcore way is to actually download the sources and build them yourself, making sure to include the appropriate -L and -l options. For a complete list of dependencies, look at the official guide on how to build qt5 from git. It has instructions on exactly which packages are needed by each qt module, and how to install them for several popular distributions. Why? Some modules (such as
qtmultimedia
) will test the build environment for available dependencies, and will adapt to this. If you are missing some dependencies you will end up with aqtmultimedia
module that does not support video or audio or both (missing pulse/alsa/gstreamer dev libs).There are two fundamental ways to build qt. You can build qt "in-tree" and "out-of-tree". I have found that the "out-of-tree" approach leaves more work on your shoulders while in the end it is the most intuitive for me. I have proceeded with this approach in this answer. "in-tree" means that you rely on the already established folder structure found in your source directory(read: lots of stuff you don't grasp easily). "out-of-tree" means that you make a build directory and start the build process from there. This is also referred to as "shadow build". The reason why I find this more intuitive is that you can look inside the shadow directory to see what files have been made/copied/changed at every step of the way, and if files are missing you know at once that something is wrong.
Some of the configure options will have adverse effects. For example the
-fully-process
option, while it promised to include everything, broke my build. Read the output of./configure --help
carefully and try to understand what each point actually means.EDIT ADDED 2016-05-04: Qt build actually produces a bunch of log files that you can inspect to get good info about why modules are missing or why things don't build as expected. I discovered this while filing a somewhat related bug while building Qt 5.6.0 under docker.
You will most likely end up with a configuration that builds only the
qtbase
module, and the rest of the modules such asqtmultimedia
andqtsvg
will have to be built after. But do not disappear, doing this is actually simpler than it sounds.The order in which you decide to build the separate modules matters. Some modules will not build if you have not first built their dependancies. For example
qtdeclarative
requiresqtscript
to be built first.I would strongly advice documenting your progress while building qt. I did this by incrementally improving a shell script that would perform all the steps that worked up this point. I will share my script in this post in the hope that it will be useful as a guide to get you up and running quickly.
Now with those general tips out of the way, here is my complete bash-script for downloading a version of qt5, configuring it and building it to taste:
EDIT: This worked OK on Ubuntu 12.04 x64 but when I replicated the process on Debian 7.0 x64 it failed with an error message: on the same format: "Project ERROR: Unknown module(s) in QT: quick svg multimediawidgets multimedia". After some troubleshooting I found that by running the configure and build steps twice in a row without cleaning solves this problem. Not an elegant solution, I know, but I was kind of hoping for some Qt5 officials/pros submitting an answer to this instead of me trying to figure out things by trial and error. I have submitted a bug report for qt about this here: https://bugreports.qt.io/browse/QTBUG-39733
To use this script, put it in a new text file such as
qt.sh
andchmod +x qt.sh
to make it executable. Make an empty dir and run the script from there.After it is complete, the resulting qmake will be under
<your dir>/qt/build/<version>/qtbase/bin
. You should be able to use this like any other qmake, from commandline, script or QtCreator. Example:If something goes wrong, you can now open the $LOG file using your favourite text editor and look at what happened.
And finally, to verify that your project was compiled with qt linked statically, you can run
ldd my_binary
and see that the list of dynamically linked libraries contains no mention of qt what-so-ever. WIN!I don't know if this is the best way to do it, so if you know a better way, or have improvements, please do not hesitate to share!