c++qtqt-creatorqmake

Setup subdirs project with app and lib subprojects for qmake in QtCreator


I'm setting up a sample subdirs projectmain with two subprojects: projectgui (app template) and and projectsub1 (lib template). I'm using QtCreator 13.0.2 with Desktop Qt 6.7.2 MSVC201964bit kit on Windows 11.

The following error occurs at the time of build:

LNK1146: no argument specified with option '/LIBPATH:'

Project Structure:

[projectmain]
|- projectmain.pro
|- [projectgui]
|  |- projectgui.pro
|- [projectsub1]
   |- projectsub1.pro
   |- projectsub1.pri

projectmain.pro:

TEMPLATE = subdirs

SUBDIRS = projectsub1 projectgui

projectsub1.subdir = projectsub1
projectgui.subdir = projectgui

projectgui.depends = projectsub1

projectgui.pro

QT       += core gui sql

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TEMPLATE = app
CONFIG += c++17

SOURCES += \
    main.cpp \
    mainwindow.cpp

HEADERS += \
    db.h \
    mainwindow.h

FORMS += \
    mainwindow.ui

DISTFILES += \
    data.db

include(../projectsub1/projectsub1.pri)

win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../projectsub1/release/ -lprojectsub1
else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../projectsub1/debug/ -lprojectsub1
else:unix: LIBS += -L$$OUT_PWD/../projectsub1/ -lprojectsub1

INCLUDEPATH += $$PWD/../projectsub1
DEPENDPATH += $$PWD/../projectsub1

projectsub1.pro:

QT -= gui
QT += sql

TEMPLATE = lib
DEFINES += PROJECTSUB1_LIBRARY
CONFIG += c++17

SOURCES += \
    customsqltablemodel.cpp \
    projectsub1.cpp

HEADERS += \
    customsqltablemodel.h \
    projectsub1_global.h \
    projectsub1.h

# Default rules for deployment.
unix {
    target.path = /usr/lib
}
!isEmpty(target.path): INSTALLS += target

DISTFILES += \
    projectsub1.pri

projectsub1.pri:

LIBTARGET = projectsub1
BASEDIR = $${PWD}
INCLUDEPATH += $${BASEDIR}
LIBS += -L$${DESTDIR} -lprojectsub1

With Desktop Qt 6.7.2 MinGW 64bit kit the build process throw the following errors:

error: cannot find -lprojectsub1
error: collect2.exe: error: ld returned 1 exit status
error: [Makefile.Debug:73: debug/projectgui.exe] Error 1

Looks like the problem with correct setup of LIBS, but I'm unable to fix after going through the following resources:

I used the following resources to setup the pro and pri files:

Any guidance is appreaciated.


Solution

  • Modifying LIBS += -L$${DESTDIR} -lprojectsub1 in projectsub1.pri on the line of LIBS += -L$$OUT_PWD/../projectsub1/debug/ -lprojectsub1 in projectgui.pro (this line was generated by "Add Library" menu option in QtCreator) seems to work. It was looking for dll in /debug/ subfolder in {DESTDIR}.