我的项目由几个子项目组成,其中一个子项目包括QGIS库。
.pro文件:
TEMPLATE = subdirs
CONFIG += ordered
SUBDIRS += \
Utils \
Maps \
GoogleMapsInterface \
Positioning \
NetworkObjects \
DataBaseManager \
SensorNetworkUI \
这是Maps的.pro文件,其中包含QGIS库:
CONFIG += c++11
CONFIG += staticlib
TEMPLATE = lib
QT += core gui
QT += widgets
QT += xml
TARGET = maps
DEFINES += MAPS_INTERFACE
INCLUDEPATH += "C:/OSGeo4W/apps/qgis/include/"
INCLUDEPATH += "C:/OSGeo4W/include/"
win32:CONFIG(Release, Debug|Release) {
LIBS += -LC:/OSGeo4W/lib/ -lQtCore4
LIBS += -LC:/OSGeo4W/lib/ -lQtGui4
LIBS += -LC:/OSGeo4W/lib/ -lQtXml4
}
else:win32:CONFIG(Debug, Debug|Release) {
PRE_TARGETDEPS += C:/OSGeo4W/lib/QtCored4.lib
PRE_TARGETDEPS += C:/OSGeo4W/lib/QtGuid4.lib
PRE_TARGETDEPS += C:/OSGeo4W/lib/QtXmld4.lib
LIBS += -LC:/OSGeo4W/lib/ -lQtCored4
LIBS += -LC:/OSGeo4W/lib/ -lQtGuid4
LIBS += -LC:/OSGeo4W/lib/ -lQtXmld4
}
LIBS += -LC:/OSGeo4W/lib -lgdal_i -lgeos_c
LIBS += -LC:/OSGeo4W/apps/qgis-dev/lib -lqgis_core -lqgis_gui
DEFINES += CORE_EXPORT=__declspec(dllexport)
DEFINES += GUI_EXPORT=__declspec(dllexport)
这是SensorNetworkUI的.pro文件:
CONFIG += console
TARGET = SensorNetwork
TEMPLATE = app
greaterThan(QT_MAJOR_VERSION, 4):
QT += widgets
QT += core gui
QT += opengl
QT += sql
QT += xml
QT += multimedia
INCLUDEPATH += ../
INCLUDEPATH += "C:/OSGeo4W/apps/qgis/include/"
INCLUDEPATH += "C:/OSGeo4W/include/"
win32:CONFIG(Release, Debug|Release) {
LIBS += -LC:/OSGeo4W/lib/ -lQtCore4
LIBS += -LC:/OSGeo4W/lib/ -lQtGui4
LIBS += -LC:/OSGeo4W/lib/ -lQtXml4
}
else:win32:CONFIG(Debug, Debug|Release) {
PRE_TARGETDEPS += C:/OSGeo4W/lib/QtCored4.lib
PRE_TARGETDEPS += C:/OSGeo4W/lib/QtGuid4.lib
PRE_TARGETDEPS += C:/OSGeo4W/lib/QtXmld4.lib
LIBS += -LC:/OSGeo4W/lib/ -lQtCored4
LIBS += -LC:/OSGeo4W/lib/ -lQtGuid4
LIBS += -LC:/OSGeo4W/lib/ -lQtXmld4
}
DEFINES += CORE_EXPORT=__declspec(dllexport)
DEFINES += GUI_EXPORT=__declspec(dllexport)
LIBS += -LC:/OSGeo4W/lib -lgdal_i -lgeos_c
LIBS += -LC:/OSGeo4W/apps/qgis-dev/lib -lqgis_core -lqgis_gui
LIBS += -L../ -ldbmanager -lsnobjects -lpositioning -lsnutils -lmaps
但是,我收到的错误是这样的:
maps.lib(moc_ClickTool.obj) : error LNK2001: unresolved external symbol "public: virtual class QVariant __thiscall QgsExpression::Function::func(class QList<class QVariant> const &,class QgsFeature const *,class QgsExpression *)" (?func@Function@QgsExpression@@UAE?AVQVariant@@ABV?$QList@VQVariant@@@@PBVQgsFeature@@PAV2@@Z)
MainWindow.obj : error LNK2001: unresolved external symbol "public: virtual class QVariant __thiscall QgsExpression::Function::func(class QList<class QVariant> const &,class QgsFeature const *,class QgsExpression *)" (?func@Function@QgsExpression@@UAE?AVQVariant@@ABV?$QList@VQVariant@@@@PBVQgsFeature@@PAV2@@Z)
我还注意到Qt Creator提供的自动完成建议不包含QGIS头文件。这是否意味着Qt Creator无法找到它们?一旦输出整个名称,它不会抛出错误。我甚至可以在Qt Creator中打开头文件。
有人可以告诉我哪里出错了吗?
编辑: 这是错误开始的地方:
Creating library ..\SensorNetwork.lib and object ..\SensorNetwork.exp
maps.lib(moc_ClickTool.obj) : error LNK2001: unresolved external symbol "public: virtual class QVariant __thiscall QgsExpression::Function::func(class QList<class QVariant> const &,class QgsFeature const *,class QgsExpression *)" (?func@Function@QgsExpression@@UAE?AVQVariant@@ABV?$QList@VQVariant@@@@PBVQgsFeature@@PAV2@@Z)
MainWindow.obj : error LNK2001: unresolved external symbol "public: virtual class QVariant __thiscall QgsExpression::Function::func(class QList<class QVariant> const &,class QgsFeature const *,class QgsExpression *)" (?func@Function@QgsExpression@@UAE?AVQVariant@@ABV?$QList@VQVariant@@@@PBVQgsFeature@@PAV2@@Z)
maps.lib(MapCanvas.obj) : error LNK2001: unresolved external symbol "public: virtual class QVariant __thiscall QgsExpression::Function::func(class QList<class QVariant> const &,class QgsFeature const *,class QgsExpression *)" (?func@Function@QgsExpression@@UAE?AVQVariant@@ABV?$QList@VQVariant@@@@PBVQgsFeature@@PAV2@@Z)
maps.lib(ClickTool.obj) : error LNK2001: unresolved external symbol "public: virtual class QVariant __thiscall QgsExpression::Function::func(class QList<class QVariant> const &,class QgsFeature const *,class QgsExpression *)" (?func@Function@QgsExpression@@UAE?AVQVariant@@ABV?$QList@VQVariant@@@@PBVQgsFeature@@PAV2@@Z)
maps.lib(moc_MapCanvas.obj) : error LNK2001: unresolved external symbol "public: virtual class QVariant __thiscall QgsExpression::Function::func(class QList<class QVariant> const &,class QgsFeature const *,class QgsExpression *)" (?func@Function@QgsExpression@@UAE?AVQVariant@@ABV?$QList@VQVariant@@@@PBVQgsFeature@@PAV2@@Z)
maps.lib(moc_ClickTool.obj) : error LNK2001: unresolved external symbol "public: virtual class QVariant __thiscall QgsExpression::Function::func(class QList<class QVariant> const &,class QgsExpressionContext const *,class QgsExpression *)" (?func@Function@QgsExpression@@UAE?AVQVariant@@ABV?$QList@VQVariant@@@@PBVQgsExpressionContext@@PAV2@@Z)
MainWindow.obj : error LNK2001: unresolved external symbol "public: virtual class QVariant __thiscall QgsExpression::Function::func(class QList<class QVariant> const &,class QgsExpressionContext const *,class QgsExpression *)" (?func@Function@QgsExpression@@UAE?AVQVariant@@ABV?$QList@VQVariant@@@@PBVQgsExpressionContext@@PAV2@@Z)
maps.lib(MapCanvas.obj) : error LNK2001: unresolved external symbol "public: virtual class QVariant __thiscall QgsExpression::Function::func(class QList<class QVariant> const &,class QgsExpressionContext const *,class QgsExpression *)" (?func@Function@QgsExpression@@UAE?AVQVariant@@ABV?$QList@VQVariant@@@@PBVQgsExpressionContext@@PAV2@@Z)
...
...
maps.lib(MapCanvas.obj) : error LNK2001: unresolved external symbol "public: static struct QMetaObject const QgsRasterDataProvider::staticMetaObject" (?staticMetaObject@QgsRasterDataProvider@@2UQMetaObject@@B)
maps.lib(MapCanvas.obj) : error LNK2001: unresolved external symbol "public: static struct QMetaObject const QgsRasterLayer::staticMetaObject" (?staticMetaObject@QgsRasterLayer@@2UQMetaObject@@B)
maps.lib(ClickTool.obj) : error LNK2001: unresolved external symbol "public: virtual void __thiscall QgsMapTool::renderComplete(void)" (?renderComplete@QgsMapTool@@UAEXXZ)
maps.lib(ClickTool.obj) : error LNK2001: unresolved external symbol "public: virtual bool __thiscall QgsMapTool::isTransient(void)const " (?isTransient@QgsMapTool@@UBE_NXZ)
maps.lib(ClickTool.obj) : error LNK2001: unresolved external symbol "public: virtual bool __thiscall QgsMapTool::isEditTool(void)const " (?isEditTool@QgsMapTool@@UBE_NXZ)
..\SensorNetwork.exe : fatal error LNK1120: 93 unresolved externals
jom: D:\Atmika\Sensor_Network\build\win32\Debug\SensorNetworkUI\Makefile.Debug [..\SensorNetwork.exe] Error 1120
jom: D:\Atmika\Sensor_Network\build\win32\Debug\SensorNetworkUI\Makefile [debug] Error 2
14:21:50: The process "D:\Qt\Qt5.7.1\Tools\QtCreator\bin\jom.exe" exited with code 2.
Error while building/deploying project Sensor_Network (kit: Desktop Qt 5.7.1 MSVC2015 32bit)
When executing step "Make"
答案 0 :(得分:0)
您的错误肯定指向链接器未在库中找到正确的符号,如“错误LNK”所示,因此先前已正确找到标头。
LIBS += ...
,核心库未链接您应该检查您指向的库文件是否存在并且对应于正确版本的QGIS。
如果动态链接,还要确保所有项目取决于它实际上包含链接器指令LIBS += ...
。
编辑:OP发现问题只是dllexport,应该是 dllimport 而不是QGIS CORE_EXPORT和GUI_EXPORT变量:
DEFINES += CORE_EXPORT=__declspec(dllimport)
DEFINES += GUI_EXPORT=__declspec(dllimport)
作为QGIS参考的详细记录的网站: https://3nids.wordpress.com/