Important: Please read the Qt Code of Conduct -

Library reference in project?

  • I'm adding attests to a Qt Quick project. Looks like the preferred way to do this is to put all C++ into a lib, and link it to the main.cpp with the UI stuff. And link to the test target. This is unfortunate, but, that's that. The issue is how to link to the library?

    This is all within a single Qt Creator project using qmake. The build system really should know where it's putting things, and handle those paths automatically. But it doesn't. As I'm searching the web, I'm seeing all kinds of convoluted .pro & pro files, at each directory level, to resolve where the library is, and setting up the linker flags.

    Is Qt Creator really this - broken? My default project, created in creator, for a single test, has three targets, with each target having three output directories (debug, profile, release). That's a lot to maintain, especially for someone coming from Xcode .

    Any help appreciated.

  • Moderators

    @treaves said:

    The issue is how to link to the library?

    What kind of linking is that - static or dynamic?

    This is all within a single Qt Creator project using qmake.

    What is? If you're going to link a library then you should have two projects - one for the library and one for the application. Am I missing something here?

    Is Qt Creator really this - broken?

    For one Qt Creator is separate from the build system and most certainly is not broken. Perhaps you could provide some parts (or the whole) project file so you could attract some suggestions? I'll give you an example of a recent project how I build my own library and then link it (note that it's shadow-built):

    QT += core network sql serialport xml
    QT -= gui
    TEMPLATE = app
    CONFIG += c++11 console
    CONFIG -= app_bundle
    INCLUDEPATH += ../qdaemon
    LIBS += -L. -lqdaemon
    MAKEFILE = ...
    # ... and so on ...

    QT += core
    QT -= gui
    unix:!macx  {
    	QT += dbus
    macx|win32  {
    	error("This library is currently not supporting your platform.")
    TARGET = qdaemon
    TEMPLATE = lib
    CONFIG += c++11
    MAKEFILE = qdaemon.make
    # ... and so on ...

  • The library import as you show it seems to work for the application, but, not for the tests. This is just a standard project created from the Qt Creator template for AutoTests.

    In the AutoTest, the structure is:


    I have the LIBS & INCLUDEPATH in both and In the path is ../../lib instead of just ../lib as it is in But the library is still not found.

  • I misspoke. app does not see the library either.

  • I'm using shadow builds too. Nothing in the compile output shows that qmake is using the correct path the the library. The path to the library will depend on if the build is debug, release, etcetera. So I'm not sure how those two lines you show could possibly work. There is no kind of substitution to the shadow build directory, or the build type.

  • I was finally able to get this working. I needed an odd combination of .pri files, and the $$OUT_PWD variable.

    Thanks to all.

Log in to reply