2017-02-13 324 views
0

我的項目由幾個子項目組成,其中一個子項目包括QGIS庫。QGIS獨立C++應用程序Qt Creator

.pro文件:

TEMPLATE = subdirs 

CONFIG += ordered 

SUBDIRS += \ 
    Utils \ 
    Maps \ 
    GoogleMapsInterface \ 
    Positioning \ 
    NetworkObjects \ 
    DataBaseManager \ 
    SensorNetworkUI \ 

這是地圖的.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 *)" (?[email protected]@[email protected]@[email protected]@[email protected]@@@@[email protected]@[email protected]@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 *)" ([email protected]@[email protected]@[email protected]@[email protected]@@@@[email protected]@[email protected]@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 *)" ([email protected]@[email protected]@[email protected]@[email protected]@@@@[email protected]@[email protected]@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 *)" ([email protected]@[email protected]@[email protected]@[email protected]@@@@[email protected]@[email protected]@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 *)" ([email protected]@[email protected]@[email protected]@[email protected]@@@@[email protected]@[email protected]@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 *)" ([email protected]@[email protected]@[email protected]@[email protected]@@@@[email protected]@[email protected]@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 *)" ([email protected]@[email protected]@[email protected]@[email protected]@@@@[email protected]@[email protected]@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 *)" ([email protected]@[email protected]@[email protected]@[email protected]@@@@[email protected]@[email protected]@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 *)" ([email protected]@[email protected]@[email protected]@[email protected]@@@@[email protected]@[email protected]@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 *)" ([email protected]@[email protected]@[email protected]@[email protected]@@@@[email protected]@[email protected]@Z) 
... 
... 
maps.lib(MapCanvas.obj) : error LNK2001: unresolved external symbol "public: static struct QMetaObject const QgsRasterDataProvider::staticMetaObject" ([email protected]@@[email protected]@B) 
maps.lib(MapCanvas.obj) : error LNK2001: unresolved external symbol "public: static struct QMetaObject const QgsRasterLayer::staticMetaObject" ([email protected]@@[email protected]@B) 
maps.lib(ClickTool.obj) : error LNK2001: unresolved external symbol "public: virtual void __thiscall QgsMapTool::renderComplete(void)" ([email protected]@@UAEXXZ) 
maps.lib(ClickTool.obj) : error LNK2001: unresolved external symbol "public: virtual bool __thiscall QgsMapTool::isTransient(void)const " ([email protected]@@UBE_NXZ) 
maps.lib(ClickTool.obj) : error LNK2001: unresolved external symbol "public: virtual bool __thiscall QgsMapTool::isEditTool(void)const " ([email protected]@@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

你的錯誤肯定指向鏈接沒有找到正確的符號庫,通過「錯誤LNK」所示,使頭部被正確地發現先前。

  1. QGIS的核心庫中沒有找到
  2. 核心庫不是在
  3. 將文庫用不同的編譯器比你的編譯,產生你的項目之一,由於鏈接到丟失的依賴LIBS += ...您的編譯器無法理解的ABI
  4. 您的頭文件和實際的庫文件不同(例如,如果它們指向不同版本的QGIS)。

您應該檢查指向的庫文件是否存在並對應於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/

+0

Thanks..but如何檢查他們是否指向正確的版本?我使用OSGeo4W來下載qgis庫和頭文件。 – user2522981

+0

我正在下載最後一個版本進行檢查,但如果您全部下載,則不太可能。版本通常直接在lib名稱中看到並指定(或者在linux上使用simlinks)。編譯「SensorNetworkUI」項目本身時是否出現錯誤?或者你有更完整的構建日誌來幫助?順便說一句,你的INCLUDEPATH你不需要報價,也不需要拖尾/ –

+0

是的..我只在編譯SensorNetworkUI項目時纔得到錯誤。 – user2522981