Qt Project with multiple subdirs, apps, libs and tests, how to set-up?
-
Dear all,
Let me start by wishing you a healthy, prosperous and /ˈkjuːt/ 2015!
I'm not sure whether this topic is more "Tools" or "Installation and Deployment" related, please feel free to move it do the other (appropriate) folder if needed!
Currently I've started a new Qt Project within Qt Creator (3.3.0 opensource) which will contain several stand-alone apps and shared libs between those apps. All apps and libraries will have their own tests and there will be an overall test-suite.
Currently I've made the following project structure / setup:
@./myProject.pro [subdir]./apps/myApp1/myApp1.pro [subdir]
./apps/myApp1/myApp1/myApp1.pro [app]
./apps/myApp1/myApp1Tests/myApp1Tests.pro [console]./apps/myApp2/myApp2.pro [subdir]
./apps/myApp2/myApp2/myApp2.pro [app]
./apps/myApp2/myApp2Tests/myApp2Tests.pro [console]./libs/myLib1/myLib1.pro [subdir]
./libs/myLib1/myLib1/myLib1.pro [lib]
./libs/myLib1/myLib1Tests/myLib1Tests.pro [console]./libs/myLib2/myLib2.pro [subdir]
./libs/myLib2/myLib2/myLib2.pro [lib]
./libs/myLib2/myLib2Tests/myLib2Tests.pro [console]./myProjectTests/myProjectTests.pro [console]@
This structure is heavily based on the following suggestion "Hello-QT":https://github.com/jtpedersen/Hello-QT following the blog from "Svenn-Arne Dragly":http://dragly.org/2014/03/13/new-project-structure-for-projects-in-qt-creator-with-unit-tests/
In my apps I would like to use the following include path:
@#include <myLib1/MyLib1.h>@
instead of
@#include <../../../libs/myLib1/myLib1/MyLib1.h>@
Without having to (re)add all the library include paths in every app when I add a new library or app.
The guidelines say that this can be achieved to add a defaults.pri file, which contains all the library include folders.
@INCLUDEPATH += $$PWD/libs/myLib1
INCLUDEPATH += $$PWD/libs/myLib2SRC_DIR = $$PWD@
Now the linker tells me the following:
@/home/mathijs/git/qt/build-myProject-Desktop_Qt_5_4_0_GCC_64bit-Debug/apps/myApp1/myApp1/../../../../myProject/apps/myApp1/myApp1/main.cpp:11: undefined reference to
MyLib1::MyLib1() /home/mathijs/git/qt/build-myProject-Desktop_Qt_5_4_0_GCC_64bit-Debug/apps/myApp1/myApp1/../../../../myProject/apps/myApp1/myApp1/main.cpp:12: undefined reference to
MyLib2::MyLib2()@So I've updated the defaults.pri file and added the LIBS:
@INCLUDEPATH += $$PWD/libs/myLib1
INCLUDEPATH += $$PWD/libs/myLib2LIBS += -lmyLib1 -lmyLib2
SRC_DIR = $$PWD@
Still no succes
@/usr/bin/ld: cannot find -lmyLib1
/usr/bin/ld: cannot find -lmyLib2@So I explicitly set the dependencies in the myProject.pro file
@TEMPLATE = subdirs
SUBDIRS +=
myApp1
myApp2
myLib1
myLib2
myProjectTestsApps
myApp1.subdir = apps/myApp1
myApp2.subdir = apps/myApp2Libs
myLib1.subdir = libs/myLib1
myLib2.subdir = libs/myLib2Dependancies
myApp1.depends = myLib1 myLib2
OTHER_FILES +=
defaults.pri@Unfortunate, this doesn't do the trick, although the libmyLib1.so and libmyLib2.so files are created in the shadow build directory.
What did I do wrong?
Many thanks in advance!
TOAOMatis
-
then maybe http://qt-project.org/forums/viewthread/13250 can help you
-
Hi,
You need to build your libraries first so use an ordered subdir project with the projects set in the correct order
-
[quote author="SGaist" date="1420497065"]Hi,
You need to build your libraries first so use an ordered subdir project with the projects set in the correct order[/quote]
I thought I did so with the toplevel project file
@# Dependancies
myApp1.depends = myLib1 myLib2@I didn't use CONFIG += ordered because of: http://blog.rburchell.com/2013/10/every-time-you-configordered-kitten-dies.html
I can see that the libraries are build first. But the linker can't find the output directories, when it tries to link the app against the two libraries.
As a matter of fact, I'm looking for a way to get the build directory for the libraries within my defaults.pri
$$OUT_PWD doesn't do the trick, while it points to the build directory of the app and not the toplevel build directory.