📜 ⬆️ ⬇️

How to compile Qgis with debugging under Windows



At work, I had to face the fact that it was necessary to find out what actions were taking place in the QGIS core. QGIS (Quantum GIS) is a free cross-platform geo-information system. The system itself is designed using the Qt toolkit. Through him, I decided to put together a project. To do this, I downloaded the qgis source from the official site and started the build. On the site itself there is an assembly guide using Qt Creator. Many articles about QGIS assembly and debugging have been read (some are even sensible). But I did not find a solution to the problems that I encountered either in the manual or in any resources. So the idea was born to write your own manual for building QuantumGIS for Windows systems using Qt Creator.

Before you collect


Initially, we download and install Qt Creator. We download from the official site . I used Qt compiled libraries. (Warning: Qgis does not officially support Qt 5. Better use Qt 4): take it from here . We put the Microsoft Windows SDK for Windows 7 and the .NET Framework 4 (ISO) (needed for setupapi)
In addition, CDB (from the MS Debugging Tools package) is required for debugging in Qt Creator. is here .

Also download and install: Cmake , Flex and Bison . From the official website download OSGeo4W for your version: here . Run it and choose: advanced installation -> install from the Internet and click all further.
')


Select the following libraries: expat, fcgi, gdal, gdal-dev, iconv, PyQt4, Qt4-Devel, qwt-devel-Qt4, sip, curl, gsl, hdf5, proj, qScintilla2, Sqlite3, libspatialIndex-devel, geos, zlib . We are waiting for it to be established.

Download the source code Qgis.

Preparation for assembly


I guess you did it. Install all that is required and download the source code. Launch Qt Creator. Then do: File -> Open file or project. Use this dialog to open the CMakeLists.txt file. It is in the source, my path is: D: \ qgis2.8.7 \ CMakeLists.txt. Next you will be asked to create an assembly site. I create a specific directory: D: / Quantum-Gis.
Next, you will be prompted to run Cmake build options. We will run it with the following parameters: -DCMAKE_BUILD_TYPE = Debug.



After running Cmake, we will specify the path to the folder where the QGIS sources are located and the path to the folder where the configuration will be written.



After that, click “Configure” and select the “NMake Makefiles” compiler and leave the “Use default native compilers” checkbox. Cmake will check the configuration and availability of the necessary components (marked in red). I will show my configuration.

BISON_EXECUTABLE C: /cygwin64/bin/bison.exe
CMAKE_INSTAL_PREFIX C: / Program Files / qgis2.8.7
EXPAT_INCLUDE_DIR C: / OSGeo4W64 / include
EXPAT_LIBRARY C: /OSGeo4W64/lib/expat.lib
FLEX_EXECUTABLE C: /cygwin64/bin/flex.exe
GDAL_INCLUDE_DIR C: / OSGeo4W64 / include
GDAL_LIBRARY C: /OSGeo4W64/lib/gdal_i.lib
GEOS_INCLUDE_DIR C: / OSGeo4W64 / include
GEOS_LIBRARY C: /OSGeo4W64/lib/geos_c.lib
POSTGRESQL_INCLUDE_DIR C: / OSGeo4W64 / include
POSTGRESQL_LIBRARY C: /OSGeo4W64/lib/libpq.lib
PROJ_INCLUDE_DIR C: / OSGeo4W64 / include
PROJ_LIBRARY C: /OSGeo4W64/lib/proj.lib
PYRCC4_PROGRAM C: /OSGeo4W64/bin/pyrcc4.exe
PYTHON_INCLUDE_PATH C: / Python27 / include
PYTHON_LIBRARY C: /Python27/libs/python27.lib;
PYUIC4_PROGRAM C: /OSGeo4W64/apps/Python27/Lib/site-packages/PyQt4/uic/pyuic.py
QSCINTILLA_INCLUDE_DIR C: / OSGeo4W64 / include / qt4
QSCINTILLA_LIBRARY C: \ OSGeo4W64 \ lib \ qscintilla2.lib
QSCI_SIP_DIR C: \ OSGeo4W64 \ include
QT_QMAKE_EXECUTABLE C: /Qt/qt-4.8.6-x64-msvc2010/qt-4.8.6-x64-msvc2010/bin/qmake.exe
QWT_INCLUDE_DIR C: / OSGeo4W64 / include / qwt
QWT_LIBRARY C: /OSGeo4W64/lib/qwt5.lib
SETUPAPI_LIBRARY C: / Program Files (x86) / Windows Kits / 8.1 / Lib / winv6.3 / um / x64 / SetupAPI.Lib
SPATIALINDEX_INCLUDE_DIR C: / OSGeo4W64 / include / spatialindex; C: / OSGeo4W64 / include
SPATIALINDEX_LIBRARY C: /OSGeo4W64/lib/spatialindex-64.lib; C: /OSGeo4W64/lib/spatialite_i.lib; C: /OSGeo4W64/lib/spatialindex_c-64.lib
SPATIALLITE_INCLUDE_DIR C: /OSGeo4W64/libspatialite-4.3.0a/src/headers
SPATIALLITE_LIBRARY C: /OSGeo4W64/lib/spatialite.lib
SQLITE3_INCLUDE_DIR C: / OSGeo4W64 / include
SQLITE3_LIBRARY C: /OSGeo4W64/sqlite3.lib
TXT2TAGS_EXECUTABLE TXT2TAGS_EXECUTABLE-NOTFOUND



The configuration should pass without errors. (Attention! I recommend setting the environment variables on folders, otherwise you will have to manually register all the paths). After a successful configuration, click "Generate" and generate configuration files. Next, close Cmake and return to Qt Creator. Click the "Finish" button.

Build project


Now for the project itself. Go to the tab "Project". At the top is the "Manage" button. In the window that opens, on the “Build and Run” tab -> “Basic”, specify the project directory, for example, D: \ Quantum-GIS. On the Text Editor tab -> File Encoding Behavior -> Default is windows-1251 / CP1251. Next, go back to the tab "Build and Run" -> "Compilers" and make sure that among the discovered there are at least some of the compilers below presented.



On the "Debuggers" tab (here) there should be these debuggers (versions may vary).



Next, select the “Qt Versions” tab, click the “Add” button and specify the path to the previously installed Qt C: \ Qt \ 4.8.6 \ bin \ qmake.exe library. In the name of the profile we register for example, Qt 4.8.6 MSVC2010 64bit.
Now you can make a bunch of tools. Go to the "Components", click "Add" and in the properties of the new bundle indicate the components. I have these:


(compiler and debugger you can have your own)

Close the "Options" by clicking the "Apply" button. The project is ready for assembly. To collect it you need to click on the hammer icon below. Compilation should be done without errors. If there are no errors, it should be reset to the created folder where the QGIS files and associated libraries were compiled:

expat.dll, freexl.dll, gdal200.dll, geos_c.dll, hdf5.dll, iconv.dll, jpeg.dll, jpeg12.dll, libcurl.dll, libpq.dll, libtiff.dll, libxml2.dll, ogdi. dll, proj.dll, qscintilla2.dll, QtCore4.dll, QtGui4.dll, QtNetwork4.dll, QtSql4.dll, QtSvg4.dll, qwt5.dll, QtXml4.dll, spatialindex-64.dll, spatialite.dll, sqlite3. dll, szip.dll, xerces-c_3_1.dll zlib.dll.

All libraries are located in the folder C: \ OSGeo4W64 \ bin, I connected Qt libraries from compiled libraries. Next, copy the folder C: \ OSGeo4W64 \ etc to the folder with the compiled QGIS files, in my case: D: \ Quantum-GIS \ output. Also copy from C: \ OSGeo4W64 \ bin two qgis.bat and o4w_env.bat batch files to the D: \ Quantum-GIS \ output \ bin directory. Let's return to the Qgis startup settings in Qt cCreator. On the "Project" tab, open the "Launch" tab. Specify the directories where the QGIS exe-file and the working directory are located.



If QGIS is running, now you can debug by pressing the button with the ladybug. Enjoy.

Possible mistakes


1. Python library. The official qgis build guide recommends choosing the python27 library installed in osge4w. I did not manage to collect with her. I downloaded a separate python27 library from the official Python website. It worked.
2. After installing Qt, create a QTDIR environment variable. If this is not done there will be problems with the Qt libraries, the project will not be able to find them. (the same should be done with Qt_MOC, QT_RCC, QT_UIC but it worked for me without it).
3. Problems with libraries. If you build the application in release mode, and the library in debug mode, then errors will occur. Ensure that both the project and the library are the same version. (I had this with the qwt library. The compiler issued QWidget: Must construct a QApplication before a QPaintDevice. Replaced the version of the library - it worked).

Hope my article will be helpful. I collected Qgis version 2.8.7 on a Windows 7 x64-bit system.

Source: https://habr.com/ru/post/281002/


All Articles