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] Compile error with libraries in a Subdirs project

[SOLVED] Compile error with libraries in a Subdirs project

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 2.7k 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.
  • R Offline
    R Offline
    Resurrection
    wrote on last edited by
    #1

    SOLVED: Even though the base library is not directly linked its header path(s) still needs to be included in any project directly or indirectly using them. Including said path solved my issue. Using absolute paths in the derived library would work as well. Or using the relative path that would work for any sub-project, i.e. all sub-projects in one directory.

    I have the following structure of a Subdirs project:

    BaseLib -> DerviedLib -> App

    The DerviedLib links to BaseLib as internal library. The DerviedLib compiles just fine however when linking and using the DerviedLib in the App I get compile error 'No such file or directory' in class from DerivedLib and specifically on the line that includes another class from BaseLib. I do have the proper macros for exporting all the classes properly.

    One solution would be to link BaseLib as well in my App but I do not want to do that since it should be part of the DerivedLib anyway (which is the whole point of this structure).

    Am I missing something here? Thanks for help.

    Secrets are power.

    1 Reply Last reply
    0
    • A Offline
      A Offline
      adolby
      wrote on last edited by
      #2

      If your App is in a different directory structure than your DerivedLib and BaseLib, you'll need to use INCLUDEPATH in your .pro file to help all of your source files find the appropriate included files.

      What does INCLUDEPATH look like in your App's .pro file?

      1 Reply Last reply
      0
      • R Offline
        R Offline
        Resurrection
        wrote on last edited by
        #3

        Thanks for reply. All libraries and the app are part of the same Subdirs project. The library projects are in subdirectory /libs/ while the App is in the main directory but it should not matter afaik, e.g.:

        BaseLib: /libs/BaseLib/BaseLib.pro
        DerivedLib: /libs/DerivedLib/DerivedLib.pro
        App: /App/App.pro

        I was hoping the BaseLib would be accessible through its derived libraries but it seems not to be the case. I cannot access its classes in Qt Creator if I only link to DerivedLib.

        BaseLib .pro file:

        @
        QT -= gui
        TARGET = PMBaseLib
        TEMPLATE = lib
        DEFINES += PMBASELIB_LIBRARY
        CONFIG += C++11

        #sources and headers

        unix
        {
        target.path = /usr/lib
        INSTALLS += target
        }
        @

        DerivedLib .pro file

        @
        QT += network
        QT -= gui
        TARGET = PMCBaseLib
        TEMPLATE = lib
        DEFINES += PMCBASELIB_LIBRARY
        CONFIG += C++11

        #sources and headers

        unix
        {
        target.path = /usr/lib
        INSTALLS += target
        }

        win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../PMBaseLib/release/ -lPMBaseLib
        else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../PMBaseLib/debug/ -lPMBaseLib
        else:unix: LIBS += -L$$OUT_PWD/../PMBaseLib/ -lPMBaseLib

        INCLUDEPATH += $$PWD/../PMBaseLib
        DEPENDPATH += $$PWD/../PMBaseLib
        @

        App .pro file

        @
        QT += core gui

        greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

        TARGET = PMClientApp
        TEMPLATE = app

        #sources and headers

        win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../libs/PMCBaseLib/release/ -lPMCBaseLib
        else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../libs/PMCBaseLib/debug/ -lPMCBaseLib
        else:unix: LIBS += -L$$OUT_PWD/../libs/PMCBaseLib/ -lPMCBaseLib

        INCLUDEPATH += $$PWD/../libs/PMCBaseLib
        DEPENDPATH += $$PWD/../libs/PMCBaseLib
        @

        Secrets are power.

        1 Reply Last reply
        0
        • A Offline
          A Offline
          adolby
          wrote on last edited by
          #4

          Your App .pro file has the INCLUDEPATH set for PMCBaseLib, which provides paths for bringing in the PMCBaseLib files you #include in your App's source files.

          When your compiler brings in the header files for PMCBaseLib following the instructions in your App .pro file, it has no way of knowing where to find the header files for PMBaseLib, which PMCBaseLib has #included.

          PMCBaseLib compiles fine because its project .pro file has an INCLUDEPATH set which allows complete paths to be created with your #include directives in your PMCBaseLib source files. That information isn't being provided in your App .pro file currently.

          You can either add PMBaseLib's include directory to your App .pro INCLUDEPATH, or add more specific paths to your PMCBaseLib #include directives. This could be an absolute or relative path.

          Note that adding PMBaseLib to your App .pro file's include path won't require you to link PMBaseLib to your App.

          1 Reply Last reply
          0
          • R Offline
            R Offline
            Resurrection
            wrote on last edited by
            #5

            I see, including the path worked. Thanks! Now I need to decide whether to keep the structure of the project and use absolute paths / include extra paths as necessary or just have everything in one directory so that the relative paths work for any combination of sub-projects.

            Secrets are power.

            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