chrise chrise - 10 months ago 68
C++ Question

c++ cannot use libraries in other 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 Cannot open include file mylibrary.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()
{
}

Answer Source

Your INCLUDEPATH looks OK, so probably the problem is in the old Makefile. You should run qmake to generate proper Makefile for your updated .pro file.

Go to Build -> Run qmake in QT Creator to do that.