簡體   English   中英

Qt Creator中具有獨立C ++應用程序的QGIS

[英]QGIS with standalone C++ application in Qt Creator

我的項目由幾個子項目組成,其中一個包括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"

您的錯誤肯定是指向鏈接器,未在庫中找到正確的符號,如“錯誤LNK”所示,因此以前已正確找到標頭。

  1. 找不到QGIS的核心庫
  2. 由於缺少一個項目中的依賴項LIBS += ... ,因此未鏈接核心庫
  3. 這些庫是使用與您不同的編譯器編譯的,從而產生了您的編譯器無法理解的ABI
  4. 標頭和實際的庫文件有所不同(例如,如果它們指向不同的QGIS版本)。

您可能應該檢查指向的庫文件是否存在並與正確的QGIS版本相對應。 如果動態鏈接,還請確保所有依賴於它的項目實際上都包含鏈接器指令LIBS += ...


編輯:OP發現問題僅僅是dllexport,對於QGIS CORE_EXPORT和GUI_EXPORT變量應該是dllimport

DEFINES += CORE_EXPORT=__declspec(dllimport)
DEFINES += GUI_EXPORT=__declspec(dllimport)

一個有據可查的站點,可作為QGIS的參考: https : //3nids.wordpress.com/

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM