c++ - How to create re-usable libraries based on qmake? -
i have multiple applications use 1 or more common libraries. libraries depend on each other.
here files tree:
libaries/ library1/ library1.pro library1.cpp library1.h library2/ library2.pro library2.cpp library2.h applications/ app1/ app1.pro main.cpp app2/ app2.pro main.cpp
app1 depends on library1. app2 depends on library1 , library2.
i'd able develop in qt creator in easy way, when open application1 have following behavior:
- application1 code available in qt creator
- library1 code available in qt creator
- compiling application1 automatically compiles library1 , puts output .dll/.so file in same directory application1 .exe.
this visual studio able years , seems such basic thing me don't understand i'm 1 having problem.
do have clue on how ? tried different solutions based on subdirs, never reach 3 points above.
edit:to clarify little, able like:
application1.pro
include("library1")
application2.pro
include("library1") include("library2")
and having working automatically. found solution requires files in libraries know "parent" doing includes, non-sense me, library should not aware of program using it.
you can project : myproject:
- project.pro
- app
- app.pro
- main.cpp
- lib1
- lib1.pro
- lib1.pri
- lib1.h
- lib1.cpp
- lib2
- lib2.pro
- lib2.pri
- lib2.h
- lib2.cpp
- app
project.pro
template = subdirs config += ordered subdirs += \ lib1 \ lib2 \ app
app.pro
qt += core qt -= gui include(../lib1/lib1.pri) include(../lib2/lib2.pri) target = app config += console config -= app_bundle template = app sources += main.cpp
main.cpp
#include <qcoreapplication> #include "lib1.h" #include "lib2.h" int main(int argc, char *argv[]) { qcoreapplication a(argc, argv); lib1 lib1(); return a.exec(); }
lib1.pro
qt -= gui target = lib1 template = lib defines += lib1_library sources += lib1.cpp headers += lib1.h\ lib1_global.h destdir = ../libs unix { target.path = /usr/lib installs += target } other_files += \ lib1.pri
lib1.pri
includepath += $$pwd/ libs += -l$$out_pwd/../libs/ -llib1
lib2.pro
qt -= gui target = lib2 template = lib defines += lib2_library sources += lib2.cpp headers += lib2.h\ lib1_global.h destdir = ../libs unix { target.path = /usr/lib installs += target } other_files += \ lib2.pri
lib2.pri
includepath += $$pwd/ libs += -l$$out_pwd/../libs/ -llib2
Comments
Post a Comment