Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Solved] Header includes with static libraries depending on each other
Forum Updated to NodeBB v4.3 + New Features

[Solved] Header includes with static libraries depending on each other

Scheduled Pinned Locked Moved General and Desktop
6 Posts 2 Posters 2.6k Views 1 Watching
  • 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.
  • E Offline
    E Offline
    Eph-
    wrote on last edited by
    #1

    Hello,

    I have some trouble figuring out how qmake handles the include dependencies of a static library that depends on another static library.

    Short version : I have 2 static libraries lib1 and lib2, with lib2 depending on lib1. An application app uses lib2. When compiling the app, should the include path (in the .pro file) only contains the lib2 headers or both lib1 and lib2 headers ? Intuitively, I would say that it should only include lib2 headers. But ... I got a compilation error saying that the headers of lib1 are not found... I find quite annoying and cumbersome to have to include both lib1 and lib2 headers, especially in case of multiple dependencies (i.e. more than 2 libraries involved). Is there a way to avoid this ?

    Long version :
    My folder structure is as below :
    @ --- src/
    lib1/
    src/ (.pro,.h,.cpp)
    lib2/
    src/ (.pro,.h,.cpp)
    app/
    src/ (.pro,.h,.cpp)
    --- build/
    lib1/
    lib1.a
    lib2/
    lib2.a
    app/
    app@

    lib1.pro
    @
    TARGET = lib1
    TEMPLATE = lib
    CONFIG += staticlib
    CONFIG += create_prl link_prl
    SOURCES += ...
    HEADERS += ...
    @

    lib2.pro
    @
    TARGET = lib2
    TEMPLATE = lib
    CONFIG += staticlib
    CONFIG += create_prl link_prl

    INCLUDEPATH += $${PRO_FILE_PWD}/../../lib1/src
    DEPENDPATH += $${PRO_FILE_PWD}/../../lib1/src
    PRE_TARGETDEPS += $${OUT_PWD}/../lib1/liblib1.a
    LIBS += -L$${OUT_PWD}/../lib1 -llib1

    SOURCES += ...
    HEADERS += ...
    @

    lib2.h
    @
    ...
    #include "header_lib1.h"
    ...
    @

    app.pro
    @
    TARGET = app
    TEMPLATE = app
    CONFIG += link_prl

    lib2

    INCLUDEPATH += $${PRO_FILE_PWD}/../../lib2/src
    DEPENDPATH +=$${PRO_FILE_PWD}/../../lib2/src
    PRE_TARGETDEPS += $${OUT_PWD}/../lib2/liblib2.a
    LIBS += -L$${OUT_PWD}/../lib2 -llib2

    SOURCES += ...
    HEADERS += ...--
    @

    When trying to compile the app, I get an error : header_lib1.h not found. I figured out 2 ways to solve this :

    In app.pro, add the following :
    @

    Include to lib1 headers

    INCLUDEPATH += $${PRO_FILE_PWD}/../../lib1/src
    DEPENDPATH += $${PRO_FILE_PWD}/../../lib1/src
    @

    Or change the include statement in lib2.h :
    @
    ...
    #include "../lib1/header_lib1.h"
    ...
    @

    But, I would like to avoid these since

    • the first solution requires to manually add the lib1 headers in the INCLUDEPATH of app.pro, which requires to keep track of the dependencies between the libraries. This is not convenient at all, especially when having multiple "cascade" dependencies. Is there a way to use lib2 in the app without explicitly referring to lib1 ?

    • the second solutions explicitly mentions the path of the lib1 headers, which I would like to avoid.

    Any suggestion is welcome =)

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

      Hi and welcome to devnet,

      What you can do is a pri file per library that you include in you app.pro

      @
      lib1.pri:
      INCLUDEPATH += $${PWD}/src
      DEPENDPATH += $${PWD}/src

      Add libs defines etc.

      app.pro:
      include(../../lib1/lib1.pri)
      @

      Hope it helps

      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
      • E Offline
        E Offline
        Eph-
        wrote on last edited by
        #3

        Thank you for your answer. Indeed, it is a bit more convenient to include a pri file. But actually, I would like to avoid to explicitly mentions the lib1 header includes in app.pro, since app depends directly on lib2, but only indirectly on lib1 (because lib2 depends on lib1). Not sure if this is possible or make sense ?

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

          If you don't have any headers from lib1 included in you lib2 headers then just include lib2.pri otherwise you'll need both

          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
          • E Offline
            E Offline
            Eph-
            wrote on last edited by
            #5

            Alright, thank you for your answers !

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

              You're welcome !

              If this answers your question, please update the thread title prepending [solved] so other forum users may know a solution has been found :)

              Happy coding !

              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