Important: Please read the Qt Code of Conduct -

Nested subdir dependencies on top-level libs

  • I have a project organized like so:


    I have a subdirs template defined at the src/ level, which defines the cmdlnie, app1, lib1, lib2. cmdline is another subdirs template, which defines cmdline_app1 and cmdline_app2.

    The problem I've run into is defining dependencies on top-level projects from within the nested subdir projects. For example, how do I define a dependency on lib1 from cmdline_app1? subdir projects are unaware of projects higher up in the hierarchy, aka cmdline subdir is unaware of lib1 project, so I can't just define cmdline_app1.depends = lib2 in the file.

  • @btse You need to add this in your .pro files in the subdirs:

            $$PWD/../../lib1/libyourlib1.a \
            $$PWD/../../lib2/libyourlib2.a \

  • @Infinity I have this already for all of my projects, in addition to DEPENDPATH. However, this only works when those dependencies have already been built at least once, aka the lib file exists. It won't build the project/lib if it hasn't been built yet.

  • @btse Can you post your file?

  • @Infinity

    TEMPLATE = subdirs
    SUBDIRS = \
    cmdline \
    app1 \
    lib1 \
    app1.depends = lib1

    TEMPLATE = subdirs
    SUBDIRS = \
    cmdline_app1 \
    # Defining dependencies on lib1 or lib2 in this file is not possible

  • I'm rushing around at work right now, so I do promise to come back and try to help more empathetically later today.

    Meanwhile, as a quick hint, I have gotten my project to do something very close (possibly identical) to what you need, by following this:

    My result ended up looking thusly:

    I'll come back in a bit when I have time to hopefully pinpoint exactly what is going wrong in your specific case. Meanwhile, HTH!

  • @KH-219Design Thanks for those, but I still don't think those capture my scenario. They detail flat structures, where all subdirs at the top level are just projects (apps or libs), and not more subdirs.

    One possible workaround is defining all projects at the top level ( explicitly, but this has a number of drawbacks, one of which it doesn't play nicely with Qt Creator. (nested subdirs are no longer shown in a tree hierarchy but are all displayed at the top level).


    SUBDIRS = cmdline/cmdline_app1
    cmdline/cmdline_app1.depends = lib1 lib2

  • Oh. Now I see. "Subdirs within subdirs." Interesting problem. (Sorry I did not read carefully enough originally.) I have a project I can use locally to poke around at this concept. I'll see if I come up with anything tomorrow.

  • I've been doing some experimenting, with no "good news".

    Meanwhile, in the throes of tweaking all my pro files and getting nowhere, it occurred to me to examine the pro files inside the source code distribution of Qt itself.

    The results are not encouraging. I found the following files using SUBDIRS and depends, and I peeked into quite a good sampling of them and none of them seem to use depends with something from a "higher" (outer, enclosing) directory. I thought if I could find even just one such example inside Qt itself, then that would unlock the mystery of how to properly do it. (I still think that! If there is such a single working example, then it will prove this is doable.)

    qtimageformats/src/ = imageformats
    qtquickcontrols2/src/ = quicktemplates2
    qtmultimedia/src/ = multimedia
    qtbase/src/ = src_tools_bootstrap
    qtbase/src/platformsupport/    input.depends += devicediscovery
    qttools/src/designer/src/    lib.depends = uiplugin
    qttools/src/            linguist.depends = designer
    qttools/src/assistant/ = help
    qtdeclarative/src/plugins/qmltooling/ = packetprotocol

    ^^ some of the places I turned to, hoping to find inspiration. None found :(

    All it would take to end the chase is one bit of documentation stating: "targets given as arguments to depends must be targets declared in the same pro file" .... or if that is not true, then an example of how to do it otherwise...

    Frustrating that I cannot find such explicit documentation. Can anyone?

  • @KH-219Design I think using the


    mechanism is a possibility ( I'll have to do some testing though.

    I guess the other solution would be to change the structure of my codebase to a more flat structure, but it's quite a large codebase so it'd take a bit of effort, and would kind of defeat the purpose of having subdirs.

Log in to reply