Important: Please read the Qt Code of Conduct -

QtCreator/QMake + SUBDIRS Template

  • I'm trying to learn QMake. I have used QtCreator to create a simple GUI project which consists of an empty form and the main.cpp code to instantiate it. It works fine.

    To learn about the subdirs template I decided to split the project up as follows:

    The intention here is to create independent libraries rather than just organizing the project into separate folders.

    The contents of the .pro files are as follows:
    @TEMPLATE = subdirs
    SUBDIRS = view program
    CONFIG += ordered
    CONFIG += debug
    CONFIG += qt@
    @TEMPLATE = lib
    CONFIG += shared
    FORMS += ./form.ui
    HEADERS += ./form.h
    SOURCES += ./form.cpp@
    @TEMPLATE = app
    SOURCES += main.cpp
    LIBS += -L../view -lview
    TARGET = ../project@

    This configuration compiles (in QtCreator) but won't run because the '' library is built in a /view subdirectory and the library can't be found. I know I could probably modify the path used to locate shared libraries but I don't want to to do that yet.

    So, in an attempt to build everything in the same directory, I have tried adding a TARGET variable to which sets the target to the same directory as the application:
    @TARGET = ../view@
    However, when I do this, although the '' library is built in the correct directory, the build then fails with this message:

    bq. error: cannot find -lview

    I don't understand why changing the TARGET (in affects the LIBS (in

    I think I must be going about this the wrong way but I can't figure out what I'm doing wrong.

    Any help would be appreciated.

  • As you talk of, I assume you're on Linux.

    The current dir (".") is not part of the library search path. So the shared library loader cannot find the lib, even if it is in the same directory as the application executable.

    You can solve this by setting the environment variable


    But it is strongly advised to not do this. See the "comment of Tobias Hunger": in another thread for an explanation.

    You can omit the TARGET setting and set


    You can set the variable in Creator, Project view, tab run settings, environment settings are on the bottom.

  • Thanks Volker, I did what you suggested and the application now runs properly.

    I didn't realize that the current directory would not be searched when looking for libraries, that's good to know.

Log in to reply