QGIS: Error LNK2019 using QApplication

272 Views Asked by At

I'm trying to create a project using the QGIS class "QApplication" but it seems to fail due to an error I can´t understand.

I'm using this build version of QGIS made for QT5.7, VS2015, W10 x64 and my main.cpp just containts the following lines:

#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();
}

And when I try to build it, these errors show up:

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 ==========

I also added to the project this "moc_qgsapplication.cpp" and wrote the line:

#define CORE_EXPORT __declspec(dllexport)

to avoid other compilation problems and linked to the project the QGIS and QT 5.7 libs.

Any idea how to fix it?

EDIT:

I have changed the two lines of main.cpp as suggested and now contains the following code:

#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();
}

but when I try to build it, these erros still show up:

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

There are 0 best solutions below