QGIS: ошибка LNK2019 при использовании QApplication

Я пытаюсь создать проект, используя класс QGIS «QApplication», но, похоже, он не работает из-за ошибки, которую я не могу понять.

я использую эта версия сборки QGIS сделана для 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 ==========

Я также добавил в проект это «moc_qgsapplication.cpp«и написал строку:

#define CORE_EXPORT __declspec(dllexport)

чтобы избежать других проблем компиляции и связанных с проектом QGIS и QT 5.7 libs.

Есть идеи как это исправить?

РЕДАКТИРОВАТЬ:

Я изменил две строки 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 ==========

1

Решение

Задача ещё не решена.

Другие решения

Других решений пока нет …

По вопросам рекламы [email protected]