Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Undefined reference on subprojects
Forum Updated to NodeBB v4.3 + New Features

Undefined reference on subprojects

Scheduled Pinned Locked Moved General and Desktop
2 Posts 1 Posters 1.4k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    Exotic_Devel
    wrote on last edited by
    #1

    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

    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
    @

    1 Reply Last reply
    0
    • E Offline
      E Offline
      Exotic_Devel
      wrote on last edited by
      #2

      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
      @

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved