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 toConfigconnec::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

    Core.pro

    @TEMPLATE = subdirs

    SUBDIRS +=
    gui
    dataaccess
    tests

    CONFIG += ordered
    @

    dataaccess.pro

    @
    #-------------------------------------------------

    Project created by QtCreator 2014-07-23T14:15:58

    #-------------------------------------------------

    QT += sql widgets

    TARGET = dataaccess
    TEMPLATE = lib
    CONFIG += staticlib

    SOURCES += 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/ -lgui

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

    win32-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
    @

    gui.pro

    @#-------------------------------------------------

    Project created by QtCreator 2014-09-02T13:39:00

    #-------------------------------------------------

    QT += widgets sql

    TARGET = gui
    TEMPLATE = lib
    CONFIG += staticlib

    SOURCES +=
    configconnec.cpp

    HEADERS +=
    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 copyuifile

    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/ -ldynamicqtwidgets

    INCLUDEPATH += $$PWD/../../../DynamicQtWidgets/build
    DEPENDPATH += $$PWD/../../../DynamicQtWidgets/build
    @

    tests.pro

    @QT += testlib sql widgets

    HEADERS +=
    testdataaccess.hpp

    SOURCES +=
    testdataaccess.cpp
    main.cpp

    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/ -ldataaccess

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

    win32-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.hpp

    SOURCES +=
    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/ -ldataaccess

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

    win32-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

    lib 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/ -lgui

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

    win32-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/ -ldynamicqtwidgets

    INCLUDEPATH += $$PWD/../../../DynamicQtWidgets/build
    DEPENDPATH += $$PWD/../../../DynamicQtWidgets/build
    @


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.