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. Compile Error: "Undefined reference to" Constructor

Compile Error: "Undefined reference to" Constructor

Scheduled Pinned Locked Moved Unsolved General and Desktop
compile-errorstatic libraryconstructor
12 Posts 4 Posters 26.4k Views
  • 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.
  • D Dong
    19 Oct 2016, 07:53

    Hi Everyone

    I got this strange Compile Error when build my project in Qt 5.4.2 on Windows
    when I compile the Application which use a library

    But it build OK on Qt 5.7

    error: undefined reference to `PropertyToCsvSetting::PropertyToCsvSetting(QString, QString, QString, QString, int)'
    

    The line where this error reported is inside the library it self.
    but when I compile the library, it compile OK.

    This is the line where error occurred

        result.append(PropertyToCsvSetting(sObjType, "Name", "Name"));
        result.append(PropertyToCsvSetting(sObjType, "Status", "Status"));
        result.append(PropertyToCsvSetting(sObjType, "Objective", "Objective"));
        result.append(PropertyToCsvSetting(sObjType, "Comment", "Comment Text"));
    

    This is my class .h file

    #ifndef PROPERTYTOCSVSETTING_H
    #define PROPERTYTOCSVSETTING_H
    
    #include <QObject>
    #include <QString>
    
    class PropertyToCsvSetting
    {
    public:
        PropertyToCsvSetting();
        PropertyToCsvSetting(QString objectType, QString propertyName, QString csvColumnName, QString stringFormat = "", int index = 0);
    
        QString ObjectType;
        QString PropertyName;
        QString CsvColumnName;
        QString StringFormat;
        int Index;
    };
    
    #endif // PROPERTYTOCSVSETTING_H
    

    This is .cpp file

    #include "propertytocsvsetting.h"
    
    PropertyToCsvSetting::PropertyToCsvSetting()
    {
    
    }
    
    PropertyToCsvSetting::PropertyToCsvSetting(QString objectType, QString propertyName, QString csvColumnName, QString stringFormat, int index)
    {
        ObjectType = objectType;
        PropertyName = propertyName;
        CsvColumnName = csvColumnName;
        StringFormat = stringFormat;
        Index = index;
    }
    
    

    Any help will be very appreciate !

    J Offline
    J Offline
    jsulm
    Lifetime Qt Champion
    wrote on 19 Oct 2016, 07:57 last edited by
    #2

    @Dong Are you linking against that library?
    You get such errors if you forget to link against a library containing the reference.

    https://forum.qt.io/topic/113070/qt-code-of-conduct

    D 1 Reply Last reply 19 Oct 2016, 08:11
    1
    • J jsulm
      19 Oct 2016, 07:57

      @Dong Are you linking against that library?
      You get such errors if you forget to link against a library containing the reference.

      D Offline
      D Offline
      Dong
      wrote on 19 Oct 2016, 08:11 last edited by
      #3

      @jsulm
      It already linked

      # Link to CommonBusiness
      win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../Business/CommonBusiness/release/ -lCommonBusiness
      else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../Business/CommonBusiness/debug/ -lCommonBusiness
      else:unix: LIBS += -L$$OUT_PWD/../Business/CommonBusiness/ -lCommonBusiness
      
      INCLUDEPATH += $$PWD/../Business/CommonBusiness
      DEPENDPATH += $$PWD/../Business/CommonBusiness
      
      win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$OUT_PWD/../Business/CommonBusiness/release/libCommonBusiness.a
      else:win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$OUT_PWD/../Business/CommonBusiness/debug/libCommonBusiness.a
      else:win32:!win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$OUT_PWD/../Business/CommonBusiness/release/CommonBusiness.lib
      else:win32:!win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$OUT_PWD/../Business/CommonBusiness/debug/CommonBusiness.lib
      else:unix: PRE_TARGETDEPS += $$OUT_PWD/../Business/CommonBusiness/libCommonBusiness.a
      
      D 1 Reply Last reply 19 Oct 2016, 08:26
      0
      • D Dong
        19 Oct 2016, 08:11

        @jsulm
        It already linked

        # Link to CommonBusiness
        win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../Business/CommonBusiness/release/ -lCommonBusiness
        else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../Business/CommonBusiness/debug/ -lCommonBusiness
        else:unix: LIBS += -L$$OUT_PWD/../Business/CommonBusiness/ -lCommonBusiness
        
        INCLUDEPATH += $$PWD/../Business/CommonBusiness
        DEPENDPATH += $$PWD/../Business/CommonBusiness
        
        win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$OUT_PWD/../Business/CommonBusiness/release/libCommonBusiness.a
        else:win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$OUT_PWD/../Business/CommonBusiness/debug/libCommonBusiness.a
        else:win32:!win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$OUT_PWD/../Business/CommonBusiness/release/CommonBusiness.lib
        else:win32:!win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$OUT_PWD/../Business/CommonBusiness/debug/CommonBusiness.lib
        else:unix: PRE_TARGETDEPS += $$OUT_PWD/../Business/CommonBusiness/libCommonBusiness.a
        
        D Offline
        D Offline
        Dong
        wrote on 19 Oct 2016, 08:26 last edited by
        #4

        Here is the Compile Output:

        windres -i [Application-Name]_resource.rc -o debug\[Application-Name]_resource_res.o --include-dir=. -DUNICODE -DQT_QML_DEBUG -DQT_DECLARATIVE_DEBUG -DQT_QUICK_LIB -DQT_WEBKITWIDGETS_LIB -DQT_WIDGETS_LIB -DQT_WEBKIT_LIB -DQT_GUI_LIB -DQT_QML_LIB -DQT_XMLPATTERNS_LIB -DQT_NETWORK_LIB -DQT_SQL_LIB -DQT_XML_LIB -DQT_CORE_LIB -DQT_NEEDS_QMAIN
        g++ -Wl,-subsystem,windows -mthreads -o debug\[Application-Name].exe object_script.[Application-Name].Debug  -lglu32 -lopengl32 -lgdi32 -luser32 -lmingw32 -LC:/Qt/Qt5.4.2/5.4/mingw491_32/lib -lqtmaind -LC:\mingw491\mingw32\lib -LC:\Utils\icu32_53_1_mingw482\lib -LC:\utils\postgresql\pgsql\lib -LC:\utils\mysql\mysql\lib -LC:\opensll\lib -lshell32 -LC:\Qt\Qt5.4.2\5.4\mingw491_32/lib "-L[Build-Path]Presentation/../Business/ServiceBusiness/debug/" -lServiceBusiness "-L[Build-Path]Presentation/../Services/SearchServices/debug/" -lSearchServices "-L[Build-Path]Presentation/../Services/Service/debug/" -lService "-L[Build-Path]Presentation/../Framework/Core/debug/" -lCore "-L[Build-Path]Presentation/../Framework/Utilities/debug/" -lUtilities "-L[Build-Path]Presentation/../Framework/SystemConst/debug/" -lSystemConst "-L[Build-Path]Presentation/../Framework/DynamicObjectCore/debug/" -lDynamicObjectCore "-L[Build-Path]Presentation/../Framework/DynamicObjectORM/debug/" -lDynamicObjectORM "-L[Build-Path]Presentation/../DatabaseEngine/debug/" -lDatabaseEngine "-L[Build-Path]Presentation/../Business/CommonBusiness/debug/" -lCommonBusiness -lQt5Quickd -lQt5WebKitWidgetsd -lQt5Widgetsd -lQt5WebKitd -lQt5Guid -lQt5Qmld -lQt5XmlPatternsd -lQt5Networkd -lQt5Sqld -lQt5Xmld -lQt5Cored debug\[Application-Name]_resource_res.o 
        [Build-Path]Presentation/../Business/CommonBusiness/debug//libCommonBusiness.a(commonbusiness.o): In function `ZN14CommonBusiness25getPropertyCampaignsToCsvEb':
        [Build-Path]Business\CommonBusiness/../../../Business/CommonBusiness/commonbusiness.cpp:1342: undefined reference to `PropertyToCsvSetting::PropertyToCsvSetting(QString, QString, QString, QString, int)'
        [Build-Path]Business\CommonBusiness/../../../Business/CommonBusiness/commonbusiness.cpp:1343: undefined reference to `PropertyToCsvSetting::PropertyToCsvSetting(QString, QString, QString, QString, int)'
        [Build-Path]Business\CommonBusiness/../../../Business/CommonBusiness/commonbusiness.cpp:1344: undefined reference to `PropertyToCsvSetting::PropertyToCsvSetting(QString, QString, QString, QString, int)'
        [Build-Path]Business\CommonBusiness/../../../Business/CommonBusiness/commonbusiness.cpp:1345: undefined reference to `PropertyToCsvSetting::PropertyToCsvSetting(QString, QString, QString, QString, int)'
        [Build-Path]Business\CommonBusiness/../../../Business/CommonBusiness/commonbusiness.cpp:1346: undefined reference to `PropertyToCsvSetting::PropertyToCsvSetting(QString, QString, QString, QString, int)'
        [Build-Path]Presentation/../Business/CommonBusiness/debug//libCommonBusiness.a(commonbusiness.o):[Build-Path]Business\CommonBusiness/../../../Business/CommonBusiness/commonbusiness.cpp:1347: more undefined references to `PropertyToCsvSetting::PropertyToCsvSetting(QString, QString, QString, QString, int)' follow
        collect2.exe: error: ld returned 1 exit status
        
        1 Reply Last reply
        0
        • V Offline
          V Offline
          VRonin
          wrote on 19 Oct 2016, 08:41 last edited by
          #5

          Looks like you did not export PropertyToCsvSetting from your library

          "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
          ~Napoleon Bonaparte

          On a crusade to banish setIndexWidget() from the holy land of Qt

          D 1 Reply Last reply 19 Oct 2016, 09:38
          2
          • V VRonin
            19 Oct 2016, 08:41

            Looks like you did not export PropertyToCsvSetting from your library

            D Offline
            D Offline
            Dong
            wrote on 19 Oct 2016, 09:38 last edited by
            #6

            @VRonin
            I don't know what you mean...

            The problem is: It compile OK on QT creator 5.7

            J V 2 Replies Last reply 19 Oct 2016, 10:00
            0
            • D Dong
              19 Oct 2016, 09:38

              @VRonin
              I don't know what you mean...

              The problem is: It compile OK on QT creator 5.7

              J Offline
              J Offline
              jsulm
              Lifetime Qt Champion
              wrote on 19 Oct 2016, 10:00 last edited by
              #7

              @Dong You should read this: http://doc.qt.io/qt-5.7/sharedlibrary.html

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              D 1 Reply Last reply 20 Oct 2016, 01:14
              2
              • D Dong
                19 Oct 2016, 09:38

                @VRonin
                I don't know what you mean...

                The problem is: It compile OK on QT creator 5.7

                V Offline
                V Offline
                VRonin
                wrote on 19 Oct 2016, 10:37 last edited by
                #8

                @Dong said in Compile Error: "Undefined reference to" Constructor:

                It compile OK on QT creator 5.7

                Ok, sorry, I missed that part. Did you build the library with Qt 5.4.2?

                "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                ~Napoleon Bonaparte

                On a crusade to banish setIndexWidget() from the holy land of Qt

                D 1 Reply Last reply 19 Oct 2016, 11:00
                2
                • V VRonin
                  19 Oct 2016, 10:37

                  @Dong said in Compile Error: "Undefined reference to" Constructor:

                  It compile OK on QT creator 5.7

                  Ok, sorry, I missed that part. Did you build the library with Qt 5.4.2?

                  D Offline
                  D Offline
                  Dong
                  wrote on 19 Oct 2016, 11:00 last edited by
                  #9

                  @VRonin
                  Yes !
                  all project are in the same SubDir Project

                  K 1 Reply Last reply 19 Oct 2016, 11:12
                  0
                  • V Offline
                    V Offline
                    VRonin
                    wrote on 19 Oct 2016, 11:04 last edited by
                    #10

                    So, I guess the library is static. could you post the 3 .pro files please?

                    "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                    ~Napoleon Bonaparte

                    On a crusade to banish setIndexWidget() from the holy land of Qt

                    1 Reply Last reply
                    2
                    • D Dong
                      19 Oct 2016, 11:00

                      @VRonin
                      Yes !
                      all project are in the same SubDir Project

                      K Offline
                      K Offline
                      kshegunov
                      Moderators
                      wrote on 19 Oct 2016, 11:12 last edited by
                      #11

                      Reran qmake and did a full rebuild?

                      Read and abide by the Qt Code of Conduct

                      1 Reply Last reply
                      2
                      • J jsulm
                        19 Oct 2016, 10:00

                        @Dong You should read this: http://doc.qt.io/qt-5.7/sharedlibrary.html

                        D Offline
                        D Offline
                        Dong
                        wrote on 20 Oct 2016, 01:14 last edited by Dong
                        #12

                        Dear All: here is my situation

                        • The class which cause compile Error is PropertyColumnMapping in DynamicObjectCore.pro
                        • Then CommonBusiness.pro using this class
                        • And Presentation linked to both CommonBusiness.pro & DynamicObjectCore.pro

                        Clean + QMake + Rebuild doesn't work.

                        Here is my Project Structure.

                        Application.pro
                        TEMPLATE = subdirs
                        CONFIG += ordered

                        SUBDIRS +=
                        Framework
                        Services
                        Business
                        Presentation
                        Updater

                        QT += qml quick widgets network sql xml

                        Business.pro
                        TEMPLATE = subdirs

                        SUBDIRS +=
                        CommonBusiness
                        ServiceBusiness

                        //Link to Framework.System

                        CommonBusiness.pro
                        QT -= gui
                        QT += qml quick sql xml xmlpatterns network

                        TARGET = CommonBusiness
                        TEMPLATE = lib
                        CONFIG += staticlib c++11

                        SOURCES += commonbusiness.cpp
                        ...

                        HEADERS += commonbusiness.h
                        ...

                        //# Link to FrameWork.DynamicObjectCore

                        DynamicObjectCore.pro
                        QT -= gui
                        QT += qml

                        TARGET = DynamicObjectCore
                        TEMPLATE = lib
                        CONFIG += staticlib c++11
                        #DEFINES += DYNAMICOBJECTCORE_LIBRARY

                        SOURCES +=
                        MetadataModel/propertycolumnmapping.cpp
                        ...

                        HEADERS +=
                        MetadataModel/propertycolumnmapping.h
                        ...
                        unix {
                        target.path = /usr/lib
                        INSTALLS += target
                        }

                        Presentation.pro
                        TEMPLATE = app

                        TARGET = [ApplicationName]

                        QT += qml quick widgets network sql xml xmlpatterns

                        //# for QT 5.4
                        qtHaveModule(webengine) {
                        QT += webengine
                        DEFINES += QT_WEBVIEW_WEBENGINE_BACKEND
                        }

                        qtHaveModule(webkitwidgets) {
                        QT += webkitwidgets
                        }

                        //# for QT 5.7
                        equals(QT_VERSION, QT_VERSION_CHECK(5, 7, 0)) {
                        QT += webview
                        DEFINES += QT_WEBVIEW_CONTROL_BACKEND
                        }

                        CONFIG += c++11

                        CONFIG(release, debug|release) {
                        CONFIG += release force_debug_info
                        }
                        RESOURCES += qml.qrc
                        shared.qrc

                        //# Link to DynamicObjectCore
                        //# Link to CommonBusiness

                        1 Reply Last reply
                        0

                        11/12

                        19 Oct 2016, 11:12

                        • Login

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