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
QtWS25 Last Chance

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.
  • DongD Offline
    DongD Offline
    Dong
    wrote on last edited by
    #1

    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 !

    jsulmJ 1 Reply Last reply
    0
    • DongD Dong

      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 !

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on 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

      DongD 1 Reply Last reply
      1
      • jsulmJ jsulm

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

        DongD Offline
        DongD Offline
        Dong
        wrote on 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
        
        DongD 1 Reply Last reply
        0
        • DongD Dong

          @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
          
          DongD Offline
          DongD Offline
          Dong
          wrote on 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
          • VRoninV Offline
            VRoninV Offline
            VRonin
            wrote on 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

            DongD 1 Reply Last reply
            2
            • VRoninV VRonin

              Looks like you did not export PropertyToCsvSetting from your library

              DongD Offline
              DongD Offline
              Dong
              wrote on last edited by
              #6

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

              The problem is: It compile OK on QT creator 5.7

              jsulmJ VRoninV 2 Replies Last reply
              0
              • DongD Dong

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

                The problem is: It compile OK on QT creator 5.7

                jsulmJ Offline
                jsulmJ Offline
                jsulm
                Lifetime Qt Champion
                wrote on 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

                DongD 1 Reply Last reply
                2
                • DongD Dong

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

                  The problem is: It compile OK on QT creator 5.7

                  VRoninV Offline
                  VRoninV Offline
                  VRonin
                  wrote on 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

                  DongD 1 Reply Last reply
                  2
                  • VRoninV VRonin

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

                    DongD Offline
                    DongD Offline
                    Dong
                    wrote on last edited by
                    #9

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

                    kshegunovK 1 Reply Last reply
                    0
                    • VRoninV Offline
                      VRoninV Offline
                      VRonin
                      wrote on 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
                      • DongD Dong

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

                        kshegunovK Offline
                        kshegunovK Offline
                        kshegunov
                        Moderators
                        wrote on 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
                        • jsulmJ jsulm

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

                          DongD Offline
                          DongD Offline
                          Dong
                          wrote on 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

                          • Login

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