Important: Please read the Qt Code of Conduct -

Qt Project with multiple subdirs, apps, libs and tests, how to set-up?

  • Dear all,

    Let me start by wishing you a healthy, prosperous and /ˈkjuːt/ 2015!

    I'm not sure whether this topic is more "Tools" or "Installation and Deployment" related, please feel free to move it do the other (appropriate) folder if needed!

    Currently I've started a new Qt Project within Qt Creator (3.3.0 opensource) which will contain several stand-alone apps and shared libs between those apps. All apps and libraries will have their own tests and there will be an overall test-suite.

    Currently I've made the following project structure / setup:
    @./ [subdir]

    ./apps/myApp1/ [subdir]
    ./apps/myApp1/myApp1/ [app]
    ./apps/myApp1/myApp1Tests/ [console]

    ./apps/myApp2/ [subdir]
    ./apps/myApp2/myApp2/ [app]
    ./apps/myApp2/myApp2Tests/ [console]

    ./libs/myLib1/ [subdir]
    ./libs/myLib1/myLib1/ [lib]
    ./libs/myLib1/myLib1Tests/ [console]

    ./libs/myLib2/ [subdir]
    ./libs/myLib2/myLib2/ [lib]
    ./libs/myLib2/myLib2Tests/ [console]

    ./myProjectTests/ [console]@

    This structure is heavily based on the following suggestion "Hello-QT": following the blog from "Svenn-Arne Dragly":

    In my apps I would like to use the following include path:

    @#include <myLib1/MyLib1.h>@

    instead of

    @#include <../../../libs/myLib1/myLib1/MyLib1.h>@

    Without having to (re)add all the library include paths in every app when I add a new library or app.

    The guidelines say that this can be achieved to add a defaults.pri file, which contains all the library include folders.

    @INCLUDEPATH += $$PWD/libs/myLib1
    INCLUDEPATH += $$PWD/libs/myLib2

    SRC_DIR = $$PWD@

    Now the linker tells me the following:

    @/home/mathijs/git/qt/build-myProject-Desktop_Qt_5_4_0_GCC_64bit-Debug/apps/myApp1/myApp1/../../../../myProject/apps/myApp1/myApp1/main.cpp:11: undefined reference to MyLib1::MyLib1() /home/mathijs/git/qt/build-myProject-Desktop_Qt_5_4_0_GCC_64bit-Debug/apps/myApp1/myApp1/../../../../myProject/apps/myApp1/myApp1/main.cpp:12: undefined reference toMyLib2::MyLib2()@

    So I've updated the defaults.pri file and added the LIBS:

    @INCLUDEPATH += $$PWD/libs/myLib1
    INCLUDEPATH += $$PWD/libs/myLib2

    LIBS += -lmyLib1 -lmyLib2

    SRC_DIR = $$PWD@

    Still no succes

    @/usr/bin/ld: cannot find -lmyLib1
    /usr/bin/ld: cannot find -lmyLib2@

    So I explicitly set the dependencies in the file

    @TEMPLATE = subdirs

    SUBDIRS +=


    myApp1.subdir = apps/myApp1
    myApp2.subdir = apps/myApp2


    myLib1.subdir = libs/myLib1
    myLib2.subdir = libs/myLib2


    myApp1.depends = myLib1 myLib2


    Unfortunate, this doesn't do the trick, although the and files are created in the shadow build directory.

    What did I do wrong?

    Many thanks in advance!


  • have you looked in side of CMake tool?
    set of CMakeLists.txt scripts can describe project with any hierarchy

  • I'm sorry. I'm using just Makefile (g++) under Ubuntu 12.04, so no CMake for me.

  • Lifetime Qt Champion


    You need to build your libraries first so use an ordered subdir project with the projects set in the correct order

  • [quote author="SGaist" date="1420497065"]Hi,

    You need to build your libraries first so use an ordered subdir project with the projects set in the correct order[/quote]

    I thought I did so with the toplevel project file
    @# Dependancies
    myApp1.depends = myLib1 myLib2@

    I didn't use CONFIG += ordered because of:

    I can see that the libraries are build first. But the linker can't find the output directories, when it tries to link the app against the two libraries.

    As a matter of fact, I'm looking for a way to get the build directory for the libraries within my defaults.pri
    $$OUT_PWD doesn't do the trick, while it points to the build directory of the app and not the toplevel build directory.

  • I use config.pri file with simple content
    @# save root directory

    and include it in all sub-projects as
    @# configuration

    to have start point APP_ROOT_DIR for folders hierarchy.

Log in to reply