Undefined reference on subprojects
-
In my project I created two static libraries, 'gui' and 'dataaccess'.
'dataaccess' uses the 'gui' library ('dataaccess' include 'gui') and 'gui' makes use of a dynamic library 'DynamicQtWidgets'. There is also a unit test that tests the 'dataaccess' library.
During compilation, the libraries are compiled without errors, but the build fails during compilation of the test with the error "undefined reference" and indicates two lines of code:@undefined reference to
Configconnec::Configconnec(QObject*)' undefined reference to
Configconnec::exec()'
@These lines are in the 'dataaccess' library code. But if the error is in the code of the library, because the library does not generate compilation errors?
If we construct libraries only, ie without the test, does not return errors. The error occurs during compilation of the test.
Below .pro files
@TEMPLATE = subdirs
SUBDIRS +=
gui
dataaccess
testsCONFIG += ordered
@@
#-------------------------------------------------Project created by QtCreator 2014-07-23T14:15:58
#-------------------------------------------------
QT += sql widgets
TARGET = dataaccess
TEMPLATE = lib
CONFIG += staticlibSOURCES += dataaccess.cpp
HEADERS += dataaccess.hpp
unix {
target.path = /usr/lib
INSTALLS += target
}win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../gui/release/ -lgui
else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../gui/debug/ -lgui
else:unix: LIBS += -L$$OUT_PWD/../gui/ -lguiINCLUDEPATH += $$PWD/../gui
DEPENDPATH += $$PWD/../guiwin32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$OUT_PWD/../gui/release/libgui.a
else:win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$OUT_PWD/../gui/debug/libgui.a
else:win32:!win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$OUT_PWD/../gui/release/gui.lib
else:win32:!win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$OUT_PWD/../gui/debug/gui.lib
else:unix: PRE_TARGETDEPS += $$OUT_PWD/../gui/libgui.a
@@#-------------------------------------------------
Project created by QtCreator 2014-09-02T13:39:00
#-------------------------------------------------
QT += widgets sql
TARGET = gui
TEMPLATE = lib
CONFIG += staticlibSOURCES +=
configconnec.cppHEADERS +=
configconnec.hpp
unix {
target.path = /usr/lib
INSTALLS += target
}OTHER_FILES += configconnec.ui
copyuifile.commands = $(COPY_DIR) $$PWD/configconnec.ui $$OUT_PWD
first.depends = $(first) copyuifile
export(first.depends)
export(copyuifile.commands)
QMAKE_EXTRA_TARGETS += first copyuifilewin32:CONFIG(release, debug|release): LIBS += -L$$PWD/../../../DynamicQtWidgets/build/release/ -ldynamicqtwidgets
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../../../DynamicQtWidgets/build/debug/ -ldynamicqtwidgets
else:unix: LIBS += -L$$PWD/../../../DynamicQtWidgets/build/ -ldynamicqtwidgetsINCLUDEPATH += $$PWD/../../../DynamicQtWidgets/build
DEPENDPATH += $$PWD/../../../DynamicQtWidgets/build
@@QT += testlib sql widgets
HEADERS +=
testdataaccess.hppSOURCES +=
testdataaccess.cpp
main.cppwin32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../dataaccess/release/ -ldataaccess
else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../dataaccess/debug/ -ldataaccess
else:unix: LIBS += -L$$OUT_PWD/../dataaccess/ -ldataaccessINCLUDEPATH += $$PWD/../dataaccess
DEPENDPATH += $$PWD/../dataaccesswin32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$OUT_PWD/../dataaccess/release/libdataaccess.a
else:win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$OUT_PWD/../dataaccess/debug/libdataaccess.a
else:win32:!win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$OUT_PWD/../dataaccess/release/dataaccess.lib
else:win32:!win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$OUT_PWD/../dataaccess/debug/dataaccess.lib
else:unix: PRE_TARGETDEPS += $$OUT_PWD/../dataaccess/libdataaccess.a
@ -
Resolved.
As "gui" and "dataaccess" are static libraries, you must include them in the test pro file and also include the shared "DynamicQtWidgets" library. My modified tests.pro
@QT += testlib sql widgets
HEADERS +=
testdataaccess.hppSOURCES +=
testdataaccess.cpp
main.cpp#lib dataaccess
win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../dataaccess/release/ -ldataaccess
else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../dataaccess/debug/ -ldataaccess
else:unix: LIBS += -L$$OUT_PWD/../dataaccess/ -ldataaccessINCLUDEPATH += $$PWD/../dataaccess
DEPENDPATH += $$PWD/../dataaccesswin32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$OUT_PWD/../dataaccess/release/libdataaccess.a
else:win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$OUT_PWD/../dataaccess/debug/libdataaccess.a
else:win32:!win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$OUT_PWD/../dataaccess/release/dataaccess.lib
else:win32:!win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$OUT_PWD/../dataaccess/debug/dataaccess.lib
else:unix: PRE_TARGETDEPS += $$OUT_PWD/../dataaccess/libdataaccess.alib GUI
win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../gui/release/ -lgui
else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../gui/debug/ -lgui
else:unix: LIBS += -L$$OUT_PWD/../gui/ -lguiINCLUDEPATH += $$PWD/../gui
DEPENDPATH += $$PWD/../guiwin32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$OUT_PWD/../gui/release/libgui.a
else:win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$OUT_PWD/../gui/debug/libgui.a
else:win32:!win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$OUT_PWD/../gui/release/gui.lib
else:win32:!win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$OUT_PWD/../gui/debug/gui.lib
else:unix: PRE_TARGETDEPS += $$OUT_PWD/../gui/libgui.a#lib DynamicQtWidgets
win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../../../DynamicQtWidgets/build/release/ -ldynamicqtwidgets
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../../../DynamicQtWidgets/build/debug/ -ldynamicqtwidgets
else:unix: LIBS += -L$$PWD/../../../DynamicQtWidgets/build/ -ldynamicqtwidgetsINCLUDEPATH += $$PWD/../../../DynamicQtWidgets/build
DEPENDPATH += $$PWD/../../../DynamicQtWidgets/build
@