qgis compile and run (win10 + vs2015)

Reprinted: https://www.jianshu.com/p/ba087f18400b

qgis compile and run (win10 + vs2015)

dc's dreams and attention

2019.02.19 00:17:14 Word count 855 Reading 3,732

1. Environment

win10 operating system;
win10 sdk ;

2. Tool preparation

IDE: vs2015, available community free version (community) ;

cmake : Cross-platform compilation and configuration tool, click here to download ;

cygwin : Unix-like environment provided on windows system for downloading required packages. 64-bit download ;

OSGeo4W : used for the release of a series of open source gis in windows system, 64-bit download ;

Among them, cygwin needs to install the following packages:

  • bison
  • flex
  • git

OSGeo4W, need to install:

  • qgis-dev-deps
    qgis-dev-deps contains a series of dependencies required by qgis. At the same time, make sure not to install the msinttypes package, because its stdint.h and vs. own will conflict.

3. Installation

vs and cmake are relatively simple.

Cygwin is  also installed step by step, until the interface of selecting the package, respectively search for the above packages, if it is not installed, it will display skip, just click to switch the version; the figure below is installed, it is displayed as keep.

image.png

 

 Choose Advanced Install for OSGeo4W . The installation path is assumed to be C:\OSGeo4W64 by default. Then install step by step until you select the package interface and enter qgis-dev-deps. Similarly, if it is not installed, it will be displayed as skip. Click to switch the version. The picture shows the installation, shown as keep.

image.png

 

4. Configuration

  • Environment The
    following is saved as a batch file C:\OSGeo4W64\qgis-dev.bat, where the specific path is replaced with the path corresponding to your own machine environment. The paths include vs, windows sdk, OSGeo, cygwin64, etc.
@echo off
set VS140COMNTOOLS = D:\Go\Program\Microsoft Visual Studio 14.0
call "D:\Go\Program\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" x64
set INCLUDE=%INCLUDE%;C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Include
set LIB=%LIB%;C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Lib
set OSGEO4W_ROOT=C:\OSGeo4W64
call "%OSGEO4W_ROOT%\bin\o4w_env.bat"
call "%OSGEO4W_ROOT%\bin\py3_env.bat"
call "%OSGEO4W_ROOT%\bin\qt5_env.bat"
set O4W_ROOT=%OSGEO4W_ROOT:\=/%
set LIB_DIR=%O4W_ROOT%
path %path%;D:\Go\Program\Microsoft Visual Studio 14.0\VC\bin
path %PATH%;D:\Go\Program\CMake\bin;E:\ProgramFiles\cygwin64\bin
@set GRASS_PREFIX=C:\OSGeo4W64\apps/grass/grass-7.6.0
@set INCLUDE=%INCLUDE%;%OSGEO4W_ROOT%\include
@set LIB=%LIB%;%OSGEO4W_ROOT%\lib;%OSGEO4W_ROOT%\lib
set LIB=%LIB%;%OSGEO4W_ROOT%\apps\Qt5\lib;%OSGEO4W_ROOT%\lib
set INCLUDE=%INCLUDE%;%OSGEO4W_ROOT%\apps\Qt5\include;%OSGEO4W_ROOT%\include
@cmd
  • cmake
    double-click the saved qgis-dev.bat above, enter cmake-gui, the cmake configuration interface will pop up, write the qgis source code directory and build directory,

     

    image.png

     

    Click configure, and select the version of vs that matches your machine in the pop-up interface. If there is an error in the process, it is easy to search for it.

     

    image.png


    Click generate after success, and click Open Project after completion, and vs will be called to open the project file (Note: At this time, the environment variable of vs is inherited from the command box).

5. Compile

After opening, there are a lot of projects, whether it is compiling or browsing, it is very slow. We only need a few core libraries, and all others are removed. Run the main program first, and add other plug-ins if necessary.

 

sln.png

  • qgis: QGIS executable program
  • qgis_native: dependencies
  • libdxfrw: dependencies
  • qgis_app:
  • qgis_analysis: dependencies
  • qgis_core: dependency, QGIS core library
  • qgis_gui: dependency, QGIS core library
  • ui: All interfaces of QGIS
  • gdalprovider: read raster data driver
  • ogrprovider: read vector data driver
  • version: version

Since the source code is utf-8 encoding and the locale of this machine is Chinese, the error "Newline in constant" may appear during compiling. You need to display and tell the compiler that the source code is utf-8:
right click -Properties-- c/c++, Command Line, Add in Addtional Options:
/source-charset:utf-8
select "RelWithDebInfo" as the compile option to compile. Since there are many source codes, compile core and native first. The overall time-consuming is relatively long, possibly more than 30 minutes.

6. Run

After the build is completed, the output is in C:\OSGeo4W64\QGIS\build\output\bin\RelWithDebInfo, as shown in the figure:

 

 

QGIS has many dependencies and can be run by setting environment variables. The following content is saved as qgis.bat.

@echo off
set OSGEO4W_ROOT=C:\OSGeo4W64
call "%OSGEO4W_ROOT%\bin\o4w_env.bat"
call "%OSGEO4W_ROOT%\bin\py3_env.bat"
call "%OSGEO4W_ROOT%\bin\qt5_env.bat"
start qgis

Double-click to run qgis.bat:

 

Development version start interface

 

qgis main interface

Reference materials:
qgis install
qgis compilation
Li Minlu qgis compilation

Guess you like

Origin blog.csdn.net/qq503690160/article/details/113615318