Compile Error: "Undefined reference to" Constructor
-
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 libraryBut 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 !
-
@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
-
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
-
@Dong You should read this: http://doc.qt.io/qt-5.7/sharedlibrary.html
-
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 += orderedSUBDIRS +=
Framework
Services
Business
Presentation
UpdaterQT += qml quick widgets network sql xml
Business.pro
TEMPLATE = subdirsSUBDIRS +=
CommonBusiness
ServiceBusiness//Link to Framework.System
CommonBusiness.pro
QT -= gui
QT += qml quick sql xml xmlpatterns networkTARGET = CommonBusiness
TEMPLATE = lib
CONFIG += staticlib c++11SOURCES += commonbusiness.cpp
...HEADERS += commonbusiness.h
...//# Link to FrameWork.DynamicObjectCore
DynamicObjectCore.pro
QT -= gui
QT += qmlTARGET = DynamicObjectCore
TEMPLATE = lib
CONFIG += staticlib c++11
#DEFINES += DYNAMICOBJECTCORE_LIBRARYSOURCES +=
MetadataModel/propertycolumnmapping.cpp
...HEADERS +=
MetadataModel/propertycolumnmapping.h
...
unix {
target.path = /usr/lib
INSTALLS += target
}Presentation.pro
TEMPLATE = appTARGET = [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