I have a rather large application I need to build/maintain so I decided to use googletest and for convenience wanted to structure the test and the application code as subprojects. I created a superproject with the following structure:
SuperProject- SuperProject.pro- defaults.pri- Application -- Application.pro -- Sources -- main.cpp -- Headers- Tests -- Tests.pro -- main.cpp -- Sources -- Headers
With superproject.pro
TEMPLATE = subdirsCONFIG += orderedSUBDIRS += \ Application \ Tests \OTHER_FILES += \ defaults.pri
With defaults.pri
INCLUDEPATH += $$PWD/Application
And Tests.pro
include(gtest_dependency.pri)include(../defaults.pri)TEMPLATE = appQT += coreCONFIG += console c++11CONFIG -= app_bundleCONFIG += threadHEADERS += tst_redoundo.hSOURCES += main.cpp
And Application.pro
include(ExcelLib/qtxlsx.pri)include(../defaults.pri)TEMPLATE = appQT += qml quickCONFIG += c++14static { # everything below takes effect with CONFIG ''= static CONFIG+= static CONFIG += staticlib # this is needed if you create a static library, not a static executable DEFINES+= STATIC message("~~~ static build ~~~") # this is for information, that the static build is done win32: TARGET = $$join(TARGET,,,s) #this adds an s in the end, so you can seperate static build from}RC_ICONS += msiconbmp.icoSOURCES += ..omittedRESOURCES += qml.qrc# Additional import path used to resolve QML modules in Qt Creator's code modelQML_IMPORT_PATH =# Additional import path used to resolve QML modules just for Qt Quick DesignerQML_DESIGNER_IMPORT_PATH =# The following define makes your compiler emit warnings if you use# any feature of Qt which as been marked deprecated (the exact warnings# depend on your compiler). Please consult the documentation of the# deprecated API in order to know how to port your code away from it.DEFINES += QT_DEPRECATED_WARNINGS# You can also make your code fail to compile if you use deprecated APIs.# In order to do so, uncomment the following line.# You can also select to disable deprecated APIs only up to a certain version of Qt.#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0# Default rules for deployment.qnx: target.path = /tmp/$${TARGET}/binelse: unix:!android: target.path = /opt/$${TARGET}/bin!isEmpty(target.path): INSTALLS += targetDISTFILES += *.priHEADERS += ..omitted
:w
Application compiles and runs fine by its own, so does the test code. But as soon as I try to include anything from Application like so
#include "util.h"#include "tst_redoundo.h"#include <gtest/gtest.h>int main(int argc, char *argv[]){ Util u; ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS();}
The code compiles but won't link with undefined reference to Util constructor. Most of the guides with the same setup as mine assumes that the template of what the test code links against is TEMPLATE = lib
but I cannot change the template from app
to lib
for Application. How do I get the linker to link against Application?