QGIS:使用QApplication错误LNK2019

时间:2016-12-21 18:46:44

标签: c++ qt visual-studio-2015 qt5 qgis

我正在尝试使用QGIS类“QApplication”创建一个项目,但由于我无法理解的错误,它似乎失败了。

我正在使用this build version of QGIS made for QT5.7, VS2015, W10 x64,而我的main.cpp只包含以下几行:

#define CORE_EXPORT __declspec(dllexport)    

#include "QGisTest.h"
#include <QtWidgets/QApplication>    

#include <qgsapplication.h>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    QGisTest w;
    w.show();
    return a.exec();
}

当我尝试构建它时,会出现这些错误:

1>------ Build started: Project: QGisTest, Configuration: Release x64 ------
1>  moc_qgsapplication.cpp
1>     Creating library C:\Users\GRODRIGUEZ\Documents\Visual Studio 2015\Projects\QGisTest\x64\Release\QGisTest.lib and object C:\Users\GRODRIGUEZ\Documents\Visual Studio 2015\Projects\QGisTest\x64\Release\QGisTest.exp
1>moc_qgsapplication.obj : error LNK2019: unresolved external symbol "private: static class QMap<class QString,class QString> QgsApplication::mSystemEnvVars21800" (?mSystemEnvVars21800@QgsApplication@@0V?$QMap@VQString@@V1@@@A) referenced in function "public: static class QMap<class QString,class QString> __cdecl QgsApplication::systemEnvVars(void)" (?systemEnvVars@QgsApplication@@SA?AV?$QMap@VQString@@V1@@@XZ)
1>main.obj : error LNK2001: unresolved external symbol "private: static class QMap<class QString,class QString> QgsApplication::mSystemEnvVars21800" (?mSystemEnvVars21800@QgsApplication@@0V?$QMap@VQString@@V1@@@A)
1>moc_qgsapplication.obj : error LNK2019: unresolved external symbol "private: static bool QgsApplication::mRunningFromBuildDir21800" (?mRunningFromBuildDir21800@QgsApplication@@0_NA) referenced in function "public: static bool __cdecl QgsApplication::isRunningFromBuildDir(void)" (?isRunningFromBuildDir@QgsApplication@@SA_NXZ)
1>main.obj : error LNK2001: unresolved external symbol "private: static bool QgsApplication::mRunningFromBuildDir21800" (?mRunningFromBuildDir21800@QgsApplication@@0_NA)
1>moc_qgsapplication.obj : error LNK2019: unresolved external symbol "private: static class QString QgsApplication::mBuildSourcePath21800" (?mBuildSourcePath21800@QgsApplication@@0VQString@@A) referenced in function "public: static class QString __cdecl QgsApplication::buildSourcePath(void)" (?buildSourcePath@QgsApplication@@SA?AVQString@@XZ)
1>main.obj : error LNK2001: unresolved external symbol "private: static class QString QgsApplication::mBuildSourcePath21800" (?mBuildSourcePath21800@QgsApplication@@0VQString@@A)
1>moc_qgsapplication.obj : error LNK2019: unresolved external symbol "private: static class QString QgsApplication::mCfgIntDir21800" (?mCfgIntDir21800@QgsApplication@@0VQString@@A) referenced in function "public: static class QString __cdecl QgsApplication::cfgIntDir(void)" (?cfgIntDir@QgsApplication@@SA?AVQString@@XZ)
1>main.obj : error LNK2001: unresolved external symbol "private: static class QString QgsApplication::mCfgIntDir21800" (?mCfgIntDir21800@QgsApplication@@0VQString@@A)
1>moc_qgsapplication.obj : error LNK2019: unresolved external symbol "private: static class QString QgsApplication::mBuildOutputPath21800" (?mBuildOutputPath21800@QgsApplication@@0VQString@@A) referenced in function "public: static class QString __cdecl QgsApplication::buildOutputPath(void)" (?buildOutputPath@QgsApplication@@SA?AVQString@@XZ)
1>main.obj : error LNK2001: unresolved external symbol "private: static class QString QgsApplication::mBuildOutputPath21800" (?mBuildOutputPath21800@QgsApplication@@0VQString@@A)
1>moc_qgsapplication.obj : error LNK2019: unresolved external symbol "private: static class QStringList QgsApplication::mGdalSkipList21800" (?mGdalSkipList21800@QgsApplication@@0VQStringList@@A) referenced in function "public: static class QStringList __cdecl QgsApplication::skippedGdalDrivers(void)" (?skippedGdalDrivers@QgsApplication@@SA?AVQStringList@@XZ)
1>main.obj : error LNK2001: unresolved external symbol "private: static class QStringList QgsApplication::mGdalSkipList21800" (?mGdalSkipList21800@QgsApplication@@0VQStringList@@A)
1>moc_qgsapplication.obj : error LNK2019: unresolved external symbol "private: static int QgsApplication::mMaxThreads21800" (?mMaxThreads21800@QgsApplication@@0HA) referenced in function "public: static int __cdecl QgsApplication::maxThreads(void)" (?maxThreads@QgsApplication@@SAHXZ)
1>main.obj : error LNK2001: unresolved external symbol "private: static int QgsApplication::mMaxThreads21800" (?mMaxThreads21800@QgsApplication@@0HA)
1>C:\Users\GRODRIGUEZ\Documents\Visual Studio 2015\Projects\QGisTest\x64\Release\\QGisTest.exe : fatal error LNK1120: 7 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

我还添加了项目this "moc_qgsapplication.cpp“并写下了这一行:

#define CORE_EXPORT __declspec(dllexport)

避免其他编译问题,并将项目链接到QGIS和QT 5.7库。

知道怎么解决吗?

编辑:

我按照建议更改了main.cpp的两行,现在包含以下代码:

#define CORE_EXPORT __declspec(dllimport)


#include "QGisTest.h"
#include <QApplication>


#include <qgsapplication.h>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    QGisTest w;
    w.show();
    return a.exec();
}

但是当我尝试构建它时,这些错误仍会出现:

1>------ Build started: Project: QGisTest, Configuration: Release x64 ------
1>  moc_qgsapplication.cpp
1>  main.cpp
1>  Generating Code...
1>     Creating library C:\Users\GRODRIGUEZ\Documents\Visual Studio 2015\Projects\QGisTest\x64\Release\QGisTest.lib and object C:\Users\GRODRIGUEZ\Documents\Visual Studio 2015\Projects\QGisTest\x64\Release\QGisTest.exp
1>moc_qgsapplication.obj : error LNK2019: unresolved external symbol "private: static class QMap<class QString,class QString> QgsApplication::mSystemEnvVars21800" (?mSystemEnvVars21800@QgsApplication@@0V?$QMap@VQString@@V1@@@A) referenced in function "public: static class QMap<class QString,class QString> __cdecl QgsApplication::systemEnvVars(void)" (?systemEnvVars@QgsApplication@@SA?AV?$QMap@VQString@@V1@@@XZ)
1>moc_qgsapplication.obj : error LNK2019: unresolved external symbol "private: static bool QgsApplication::mRunningFromBuildDir21800" (?mRunningFromBuildDir21800@QgsApplication@@0_NA) referenced in function "public: static bool __cdecl QgsApplication::isRunningFromBuildDir(void)" (?isRunningFromBuildDir@QgsApplication@@SA_NXZ)
1>moc_qgsapplication.obj : error LNK2019: unresolved external symbol "private: static class QString QgsApplication::mBuildSourcePath21800" (?mBuildSourcePath21800@QgsApplication@@0VQString@@A) referenced in function "public: static class QString __cdecl QgsApplication::buildSourcePath(void)" (?buildSourcePath@QgsApplication@@SA?AVQString@@XZ)
1>moc_qgsapplication.obj : error LNK2019: unresolved external symbol "private: static class QString QgsApplication::mCfgIntDir21800" (?mCfgIntDir21800@QgsApplication@@0VQString@@A) referenced in function "public: static class QString __cdecl QgsApplication::cfgIntDir(void)" (?cfgIntDir@QgsApplication@@SA?AVQString@@XZ)
1>moc_qgsapplication.obj : error LNK2019: unresolved external symbol "private: static class QString QgsApplication::mBuildOutputPath21800" (?mBuildOutputPath21800@QgsApplication@@0VQString@@A) referenced in function "public: static class QString __cdecl QgsApplication::buildOutputPath(void)" (?buildOutputPath@QgsApplication@@SA?AVQString@@XZ)
1>moc_qgsapplication.obj : error LNK2019: unresolved external symbol "private: static class QStringList QgsApplication::mGdalSkipList21800" (?mGdalSkipList21800@QgsApplication@@0VQStringList@@A) referenced in function "public: static class QStringList __cdecl QgsApplication::skippedGdalDrivers(void)" (?skippedGdalDrivers@QgsApplication@@SA?AVQStringList@@XZ)
1>moc_qgsapplication.obj : error LNK2019: unresolved external symbol "private: static int QgsApplication::mMaxThreads21800" (?mMaxThreads21800@QgsApplication@@0HA) referenced in function "public: static int __cdecl QgsApplication::maxThreads(void)" (?maxThreads@QgsApplication@@SAHXZ)
1>C:\Users\GRODRIGUEZ\Documents\Visual Studio 2015\Projects\QGisTest\x64\Release\\QGisTest.exe : fatal error LNK1120: 7 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

0 个答案:

没有答案