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. Using libraries in libraries
Forum Updated to NodeBB v4.3 + New Features

Using libraries in libraries

Scheduled Pinned Locked Moved Solved General and Desktop
9 Posts 2 Posters 1.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.
  • Z Offline
    Z Offline
    zicx
    wrote on last edited by zicx
    #1

    Is it possible to use libraries in libraries?

    I added some libraries, both shared and static and got them to work so that I can use them in a desktop application. However, when I try to use a static library in another static library or a shared library in another shared library that does not seem to work.
    I get the error

    C:\CPP\Test\SharedLib\sharedlib.cpp:4: error: C1083: Cannot open include file: 'sharedlib_2.h': No such file or directory
    

    Is there a way around it? If not, what is the best way to structure projects/libraries. It seems to be very limiting that that libraries cant use other libraries

    This is my application's .pro where I can use he library

    QT += core
    QT -= gui
    
    CONFIG += c++11
    
    TARGET = Test
    CONFIG += console
    CONFIG -= app_bundle
    
    TEMPLATE = app
    
    SOURCES += main.cpp
    
    win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../SharedLib/release/ -lSharedLib
    else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../SharedLib/debug/ -lSharedLib
    
    INCLUDEPATH += $$PWD/../SharedLib
    DEPENDPATH += $$PWD/../SharedLib
    
    win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../SharedLib_2/release/ -lSharedLib_2
    else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../SharedLib_2/debug/ -lSharedLib_2
    
    INCLUDEPATH += $$PWD/../SharedLib_2
    DEPENDPATH += $$PWD/../SharedLib_2
    

    and the .pro of SharedLib which is supposed to use SharedLib_2

    QT       -= gui
    
    TARGET = SharedLib
    TEMPLATE = lib
    
    DEFINES += SHAREDLIB_LIBRARY
    
    SOURCES += sharedlib.cpp
    
    HEADERS += sharedlib.h\
            sharedlib_global.h
    
    unix {
        target.path = /usr/lib
        INSTALLS += target
    }
    
    win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../SharedLib_2/release/ -lSharedLib_2
    else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../SharedLib_2/debug/ -lSharedLib_2
    
    INCLUDEPATH += $$PWD/../SharedLib_2
    DEPENDPATH += $$PWD/../SharedLib_2
    

    I added them both via the automatic add library and the lines are identically... so I would have expected this to work

    includes are

    application

    #include <QCoreApplication>
    
    #include "sharedlib.h"
    #include "sharedlib_2.h"
    
    int main(int argc, char *argv[])
    {
        QCoreApplication a(argc, argv);
    
        SharedLib sl;
        SharedLib_2 sl_2;
    
        return a.exec();
    }
    

    sharedLib

    #include "sharedlib.h"
    
    #include "sharedlib_2.h"  // ERROR HERE
    
    SharedLib::SharedLib()
    {
    }
    
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Not that I want to be picky but you write that you get error Cannot open include file mylibrary.h: no such file or directory but in what you provide there's not mylibrary.h that can be seen.

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

      Z 1 Reply Last reply
      1
      • SGaistS SGaist

        Hi,

        Not that I want to be picky but you write that you get error Cannot open include file mylibrary.h: no such file or directory but in what you provide there's not mylibrary.h that can be seen.

        Z Offline
        Z Offline
        zicx
        wrote on last edited by
        #3

        @SGaist
        Thanks for pointing out. Edit and copied the actual error

        1 Reply Last reply
        0
        • Z Offline
          Z Offline
          zicx
          wrote on last edited by
          #4

          As a first simple question.... Is it possible to use libraries in libraries or does that generally not work?

          If it is possible... second question: why does it not work here?

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

            Sure it's possible, otherwise how you could any library that has dependencies work ?

            Did you re-run qmake after modifying your libs .pro file ?

            One thing that is not clear, how are these projects related ? One common with sub-projects or each his own ?

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

            Z 1 Reply Last reply
            0
            • SGaistS SGaist

              Sure it's possible, otherwise how you could any library that has dependencies work ?

              Did you re-run qmake after modifying your libs .pro file ?

              One thing that is not clear, how are these projects related ? One common with sub-projects or each his own ?

              Z Offline
              Z Offline
              zicx
              wrote on last edited by
              #6

              @SGaist

              I did rerun qmake

              Both libraries are separate projects ( I think.. ). When creating them the drop down "Add as subproject to project: is greyed out, I cant chose anything there

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

                Where are they located on your filesystem ?
                Where exactly did you build them ?

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

                Z 1 Reply Last reply
                0
                • Z Offline
                  Z Offline
                  zicx
                  wrote on last edited by
                  #8

                  @zicx

                  I misunderstood qmake. thought it runs on all projects. rerunning it on all individual projects fixed it

                  1 Reply Last reply
                  0
                  • SGaistS SGaist

                    Where are they located on your filesystem ?
                    Where exactly did you build them ?

                    Z Offline
                    Z Offline
                    zicx
                    wrote on last edited by
                    #9

                    @SGaist

                    Thanks a lot for your help

                    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