I have a Qt project (called "scanner") built with QMake, where I have 2 subprojects : a static library called "scannerlib" and an application using that lib, called "app" (which, at the moment, is just a main.cpp file)
My "scanner" folder contains the file scanner.pro :
QT += core testlib
QT -= gui
CONFIG += c++14
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = subdirs
SUBDIRS = app scannerlib
app.depends = scannerlib
And two subfolders, containing a .pro file and source file related. scannerlib/scannerlib.pro :
TARGET = scannerlib
TEMPLATE = lib
CONFIG += staticlib
#I ommited SOURCES and HEADERS here for brevity
app/app.pro :
TARGET = app
TEMPLATE = app
SOURCES = main.cpp
INCLUDEPATH += ../scannerlib
LIBS += -L../scannerlib -lscannerlib
I successfully build libscanner, but I can't link it in "app".
error : cannot find -lscannerlib
After checking, libscannerlib.a has been successfully built, so it should not be a problem. If I remove -lscannerlib, I get an undefined reference. Which seems legit.
I can get a successful build if I move the created "libscannerlib.a" from the build folder to scanner/scannerlib, which allows qmake to find it.
So, the problem looks like it comes from "-L../scannerlib". What should I put there in such a way that qmake find the lib in the build folder ?
You may use DESTDIR
in your both scannerlib
and app
projects.
scannerlib/scannerlib.pro :
TARGET = scannerlib
TEMPLATE = lib
CONFIG += staticlib
DESTDIR = ../bin
app/app.pro :
TARGET = app
TEMPLATE = app
SOURCES = main.cpp
DESTDIR = ../bin
INCLUDEPATH += ../scannerlib
LIBS *= -L$$OUT_PWD/$$DESTDIR -lscannerlib
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With