Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Using libraries in libraries



  • 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()
    {
    }

  • Lifetime Qt Champion

    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.



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



  • 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?


  • Lifetime Qt Champion

    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 ?



  • @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


  • Lifetime Qt Champion

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



  • @zicx

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



  • @SGaist

    Thanks a lot for your help


Log in to reply