I have a project with 5-6 libraries and one executable. The executable depends on the libraries, and some libraries depend on other libraries. How can I specify a build order so the dependencies are built before they are needed?
2 Answers
Update: (Feb 2021)
- Oct 2018 - Qt decided to deprecate Qbs and redirect its resources to increase support for CMake.
- Oct 2020 - CMake is the build system for Qt 6.
Please consume the advice in the (old) answer below in light of this new information.
Although this question has been answered and accepted a long time ago, I feel the need to add another answer; I honestly think that there is a better answer.
I consider CONFIG += ordered
harmful and a bad habit. It is probably something that was a bit prematurely introduced by the qmake developers. And there are strong opponents to its use. The drawbacks are these:
- it does not define the dependencies, it just names a build order
- it hammers multicore build times
- it prevents Qt developers from implementing meaningful features
Therefore, I suggest to change your project file as follows:
TEMPLATE = subdirs
SUBDIRS += Utility GraphicModule PackingLib Core GameProto
GameProto.depends = Core
Core.depends = PackingLib
PackingLib.depends = GraphicModule
GraphicModule.depends = Utility
This way the dependencies are clearly defined. You can also think of other, more complicated dependency hierarchies which are possible this way and absolutely impossible with the build order.
Unfortunately, qmake
is not the best tool when it comes to larger projects with deep sub-project hierarchies. Problems seen with larger projects are these:
- it is not possible to define dependencies to sub-projects higher up in the hierarchy
Run qmake
takes an extremely long time to execute- long compile time because the dependencies are not handled properly and too many unnecessary compile steps executed
- sometimes
qmake
is not able to correctly calculate sub-project dependencies which makes it necessary to compile sub-projects separately
There mainly two ways to address these issues:
- Rewrite your project to a flat hierarchy. All executables, static and dynamic libraries should be in the topmost level. Use two or more levels only for sub-projects where you absolutely cannot avoid it. (e.g. a dynamic library that comprises of static libraries) This will result in shorter
qmake
run times and shorter compilation times. However, even this approach may fail at times. - Change to a different make tool, like
cmake
. Seriously.Cmake
is a mature product and the support from within Qt Creator is comparable toqmake
.
Because of the well known problems with qmake
, the Qt Company has already decided to introduce a new make tool QBS
. However, the use of this tool is not as simple as it may look on first impression. There is no easy transition from qmake
to QBS
, especially for more complex projects. The Javascript-like syntax of the QBS
language is not easy to grasp and documentation is scarce.
There are IMHO only two other tools available that are of the caliber to replace qmake
:
-
1This is not only better in terms of performance but also in terms of readability. Definitely the right answer for the question at hand. – rbaleksandar Nov 11 '16 at 09:14
Ok. I found the solution.Just add ordered to CONFIG and recite subdirs in correct order
CONFIG += ordered
SUBDIRS += Utility GraphicModule PackingLib Core GameProto
For me this work fine

- 1,313
- 4
- 17
- 33
-
3The 'CONFIG += ordered' can have a devastating effect on multicore compile times. Please consider strict definition of dependencies as in my answer below. – user23573 Sep 01 '15 at 12:33
-
1@BogdanWilli No, it will not, unless you have a terribly slow single-threaded linker; aside from that, use `jom` on Windows and `make -jN` (with N==Ncores/threads) on *NIX; funny thing is, even if linking (which *is* single-threaded usually) takes lots of time, it means, there are lots of object files to link, compiling which obviously has had much longer time (== build times are hardly dominated by linking); another thing with ordered configs is greater reprodiciblity of builds (and easier error handling, despite things being parallel for each project) – mlvljr Nov 21 '16 at 18:57
-
1@mlvljr, Link time is always an issue. See the efforts by clang and gcc to reduce that time. Qmake has been updated and behaves different than 4 years ago. But the situation is still far from good. Instead of fixing qmake, the developers have created a new tool called QBS (which has it's own problems). There is a comment in their bugtracker saying that they will not fix qmake build-order issues because it is too difficult in the presence of the "ordered" argument. – user23573 Nov 22 '16 at 10:15
-
@BogdanWilli may be, to each their own, though, you just have to be able to cook it right with the tools of your choice (mine is ordered builds); worst case is relying on internet advice, while not knowing the rationale behind it :) – mlvljr Nov 22 '16 at 19:58