Qt and QGis integration ERROR `__imp__ZN14QgsApplicationC1ERiPPcbRK7QStringS5_'
-
OS : windows 10 64 bit x64
Qt Creator 4.11.1
Based on Qt 5.14.1 (MSVC 2017, 32 bit)
Qt compiler : MinGW 7.3.0 64 bit for c++
QGIS : Online (OSGeo4W) installer: many version installed by OSGeo4W installerCan any one help me to resolve this issue?
Facing error
C:\Users\amanjaiswal\Documents\untitled7\main.cpp:7: error: undefined reference to
__imp__ZN14QgsApplicationC1ERiPPcbRK7QStringS5_' C:\Users\amanjaiswal\Documents\untitled7\main.cpp:8: error: undefined reference to
__imp__ZN14QgsApplication13setPrefixPathERK7QStringb'
C:\Users\amanjaiswal\Documents\untitled7\main.cpp:11: error: undefined reference to__imp__ZN14QgsApplication8exitQgisEv' C:\Users\amanjaiswal\Documents\untitled7\main.cpp:7: error: undefined reference to
__imp__ZN14QgsApplicationD1Ev'
C:\Users\amanjaiswal\Documents\untitled7\main.cpp:7: error: undefined reference to__imp__ZN14QgsApplicationD1Ev' C:\OSGeo4W\apps\qgis-ltr-dev\include\qgis.h:405: error: undefined reference to
__imp__ZN4Qgis16staticMetaObjectE'
:-1: error: collect2.exe: error: ld returned 1 exit status -
You can not mix MSVC and MinGW c++ libraries - if you want to use MinGW/g++ then you also have to compile OSGeo with MinGW which I doubt you have.
-
Can you guide to compile OSGeo with MinGW? @Christian-Ehrlicher . As in OSGeo installer i don't get option to choose MinGw or MSVC.
-
@Aman55 said in Qt and QGis integration ERROR `__imp__ZN14QgsApplicationC1ERiPPcbRK7QStringS5_':
Can you guide to compile OSGeo with MinGW?
Please refer to their documentation: https://github.com/qgis/QGIS/blob/master/INSTALL.md
-
I have downloaded visual studio 2017 and I updated my compiler with Qt Compiler MSVC 2017. got an error
C:\OSGeo4W\apps\qgis-ltr-dev\include\qgssettingsentry.h:31: error: C7525: inline variables require at least '/std:c++17' @Christian-Ehrlicher @jsulm -
@Aman55 said in Qt and QGis integration ERROR `__imp__ZN14QgsApplicationC1ERiPPcbRK7QStringS5_':
can't say yes. if it comes with download only.
You can simply check what DLLs where installed.
Does release build work? -
@jsulm Yes release build work for the above main.cpp code. currently used to load shp file and gives error
C:\OSGeo4W\apps\qgis-ltr-dev\include\qgsabstractgeometry.h:596: error: C2065: 'M_PI': undeclared identifier
C:\OSGeo4W\apps\qgis-ltr-dev\include\qgsvector.h:175: error: C2065: 'M_PI': undeclared identifier
C:\OSGeo4W\apps\qgis-ltr-dev\include\qgsgeometry.h:2757: error: C2065: 'M_PI': undeclared identifier// main.cpp int main(int argc, char *argv[]) { QApplication a(argc, argv); // 1. Initialize QGIS QgsApplication::setPrefixPath("C:/OSGeo4W64/apps/qgis-ltr-dev", true); // Replace with your QGIS installation path QgsApplication::init(); // 2. Specify the path to your SHP file QString shpFilePath = ":/gis_osm_barriers_07_1.shp"; // Replace with the actual path // 3. Check if the file exists QFileInfo fileInfo(shpFilePath); if (!fileInfo.exists()) { qDebug() << "Error: Shapefile not found at" << shpFilePath; QgsApplication::exit(); return 1; } // 4. Create a QgsVectorLayer QgsVectorLayer *vlayer = new QgsVectorLayer(shpFilePath, "shapefile_layer", "ogr"); // "ogr" is the data provider // 5. Check if the layer is valid if (!vlayer->isValid()) { qDebug() << "Error: Could not load shapefile:" << vlayer->error().message(); delete vlayer; QgsApplication::exit(); return 1; } // 6. Accessing Feature Information (Example) qDebug() << "Number of features:" << vlayer->featureCount(); // 7. Clean up delete vlayer; // Important to prevent memory leaks QgsApplication::exit(); return 0; }
-
@Aman55 Then you probably only have the release versions of these libs which can't be mixed with a debug build.
"Yes release build work for the above main.cpp code. currently used to load shp file and gives error" - I don't get it. How can it work if you get compiler errors? What is the very first error?
-
@jsulm Previously i have only use qgsapplication header as
#include <QApplication> #include <qgsapplication.h> int main(int argc, char *argv[]) { QgsApplication app(argc, argv, true); QgsApplication::setPrefixPath("C:/OSGeo4W64/apps/qgis-ltr-dev", true); int retval = app.exec(); // QgsApplication::exitQgis(); return retval; }
so there is no need for other headerfiles. then it build successfully. Now i am reading shp file where it does not locate M_PI Macro