Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. Getting subdirs project to work: subproject can't find static library binaries of other project

Getting subdirs project to work: subproject can't find static library binaries of other project

Scheduled Pinned Locked Moved Unsolved Qt Creator and other tools
2 Posts 2 Posters 345 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    DerManu 0
    wrote on last edited by DerManu 0
    #1

    Hi all,
    I've stumbled upon a rather unexpected issue with qmake and project dependencies.
    Let's assume we have a static library and an application which depends on the static library. Naturally I'd want the build system to recompile the library if something has changed in its sources, before going on to building the application.

    So this is what commonly is done with the subdirs project type, which in my case is placed next to the app project file. I thus have the following structure:

    BigProject/
    ├── theApp/
    │   ├── abcapp.pro
    │   ├── buildall.pro  //<- the subdirs project
    │   └── (source files...)
    └── theLibrary/
        ├── abclibrary.pro
        ├── abclibrary.pri
        └── (source files...)
    

    The Library
    The abclibrary.pro is nothing special, it looks something like this:

    QT += ...
    TEMPLATE = lib
    CONFIG += qt staticlib
    TARGET = abclibrary
    HEADERS += ...
    SOURCES += ...
    

    Note that I'm not explicitly defining the destination of compilaton outputs, like DESTDIR, MOC_DIR, OBJECTS_DIR, etc. because I want QtCreator's shadowbuild feature to place them wherever it points to. Typically this will be a directory above the source directory, and named according to the build type, platform, target name etc. to prevent clashes of previously existing builds. So in this example, the shadowbuild will happen in BigProject/build-abclibrary-staticlib-Debug/.

    Building the library through abclibrary.pro directly works as expected.

    The Application
    The abcapp.pro is also nothing too peculiar:

    QT += ...
    TEMPLATE = app
    TARGET = abcapp
    HEADERS += ...
    SOURCES += ...
    
    include(../theLibrary/abclibrary.pri)
    

    Notice how I'm not hardcoding here how to link to abclibrary (e.g. by hardcoding LIBS += -L../theLibrary -labclibrary) because I don't know where the binaries will actually end up when building the library. So this is deferred to the .pri file in the library directory which looks like this:

    BASEDIR   = $${PWD}
    INCLUDEPATH *= $${BASEDIR}/
    LIBS += -L$$shadowed($$PWD) -labclibrary
    

    And finally here's the subdirs project buildall.pro:

    TEMPLATE = subdirs
    SUBDIRS = abclibrary abcapp
    abclibrary.file = ../theLibrary/abclibrary.pro
    abcapp.file  = ./abcapp.pro
    
    abcapp.depends = abclibrary
    

    Here's the issue: It's not working™.
    In the final linking stage, I can see that the app is being built with the parameter "-L -labclibrary", so it seems the string $$shadowed($$PWD) is empty, and doesn't contain the true directory where the abclibrary binaries are placed. Now I've derived this structure from various tutorials on the internet, as well as the official documentation regarding the subdirs template, and I didn't expect something so bread-and-butter in terms of build management to be so hard with qmake. I've also tried using $$DESTDIR, which turned out to also be an empty string in the decisive build moment.

    How do you guys do it? Where is my mistake?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      IIRC, I used a combo of DESTDIR and $$OUT_PWD to put all libraries in a common folder so then it's easier to link the application to them.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved