I try to use multiple subprojects with dynamic linked libraries in Qt 5.x (tried with 5,13 and 5.8).
I used the Qt Creator and created one main widget project, and some simple libaries.
In main project i used the Qt creator to include another project as internal library.
I also added the dependencies in the .pro file of the top level folder
TEMPLATE = subdirs
SUBDIRS += \
bla \
blub \
main \
untitled
bla.depends = blub untitled
main.depends = bla blub
In each of th subprojects is a *_global with defines the EXPORT
#if defined(BLA_LIBRARY)
# define BLA_EXPORT Q_DECL_EXPORT
#else
# define BLA_EXPORT Q_DECL_IMPORT
#endif
In the mainwindow.cpp I can include the header file of another subproject, e.g.
#include "bla.h"
...
Bla *bla = new Bla();
There is also no problem to put the #include "bla.h" in mainwindow.h
I can also include e.g. blub.h in main.
My problem is to use one of the other libraries from another library.
I do the same steps.
In bla.pro
win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../blub/release/ -lblub
else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../blub/debug/ -lblub
else:unix: LIBS += -L$$OUT_PWD/../blub/ -lblub
INCLUDEPATH += $$PWD/../blub
DEPENDPATH += $$PWD/../blub
Now as soon as i try to "#include blub.h" the following problem occurs:
If i do it in a header of bla.h an error occurs that file cannot be found. (No such file or directory)
Funnily i can include it in bla.c but then it crashes during execution as soon as an object blub is created.
Now i have a problem understanding the behaviour of Qt.
If i include blub.h in mainwindow.h I can also include blub.h in the other project in bla.h. No error, no missing file, o crash during execution. But this "fix" seem to be totally wrong.
Do i have some misunderstanding in using libraries form other libraries? Why can i only include it when including it from widget which does not use the library in first place?
Background: I wanted to use a strategy pattern and have interfaces to different strategies. The strategy should be encapsulated further and not be visible from UI at frist place.