简体   繁体   English

Qt Creator中具有独立C ++应用程序的QGIS

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

My projects consists of several subprojects, one of which includes QGIS libraries. 我的项目由几个子项目组成,其中一个包括QGIS库。

.pro file : .pro文件:

TEMPLATE = subdirs

CONFIG += ordered

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

This is the .pro file of Maps, that includes the QGIS libraries: 这是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)

This is the .pro file for SensorNetworkUI: 这是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

However, I am getting errors like these: 但是,我收到类似以下的错误:

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)

I also noticed that the auto complete suggestions given by Qt Creator don't include the QGIS header files. 我还注意到Qt Creator提供的自动完成建议不包括QGIS头文件。 Does this mean Qt Creator is not able to find them? 这是否意味着Qt Creator无法找到它们? It does not throw up errors once the entire name has been typed out. 输入完整的名称后,它不会引发错误。 I can even open said header files in Qt Creator. 我什至可以在Qt Creator中打开上述头文件。

Can someone please tell me where I am going wrong? 有人可以告诉我我要去哪里了吗?

EDIT: This is where the error begins: 编辑:这是错误开始的地方:

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"

Your error definitely points to the linker not finding the correct symbol in the library, as indicated by "error LNK", so headers were correctly found previously. 您的错误肯定是指向链接器,未在库中找到正确的符号,如“错误LNK”所示,因此以前已正确找到标头。

  1. The core library of QGIS is not found 找不到QGIS的核心库
  2. The core library is not linked due to a missing dependency LIBS += ... in one of your projects 由于缺少一个项目中的依赖项LIBS += ... ,因此未链接核心库
  3. The libraries were compiled with a different compiler than yours, producing an ABI that is not understood by your compiler 这些库是使用与您不同的编译器编译的,从而产生了您的编译器无法理解的ABI
  4. Your headers and the actual libary differ (for instance if they point to different version QGIS). 标头和实际的库文件有所不同(例如,如果它们指向不同的QGIS版本)。

You should probably check that the library files you point to are present and corresponds to the right version of QGIS. 您可能应该检查指向的库文件是否存在并与正确的QGIS版本相对应。 If linking dynamically, also make sure that all projects depending on it actually include the linker directive LIBS += ... . 如果动态链接,还请确保所有依赖于它的项目实际上都包含链接器指令LIBS += ...


EDIT: The OP found the problem to be simply the dllexport, that should be dllimport instead for QGIS CORE_EXPORT and GUI_EXPORT variables: 编辑:OP发现问题仅仅是dllexport,对于QGIS CORE_EXPORT和GUI_EXPORT变量应该是dllimport

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

A well documented site as reference for QGIS: https://3nids.wordpress.com/ 一个有据可查的站点,可作为QGIS的参考: https : //3nids.wordpress.com/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM