分享

QGIS编译 3.14.6+win10+vs2015

 LZS2851 2021-07-22

概述

整体步骤是根据官方的安装指南来完成,因为安装指南比较简略,并且还存在一些瑕疵,导致完全根据官方指南自己编译会出不少问题。官网详情:https://github.com/qgis/QGIS/blob/release-3_14/INSTALL.md
在此详细描述一下具体做法。

安装过程

我会粘贴进部分官方的编译指南(英语部分)
下载vs2015社区版本,这个是在线安装的版本,装完大概需要8.1G硬盘空间,尽量安装在默认路径,反正我没改。

下载VS2015并安装

4.1.1. Visual Studio 2015 Community Edition

http://download.microsoft.com/download/D/2/3/D23F4D0F-BA2D-4600-8725-6CCECEA05196/vs_community_ENU.exe

安装时选择自定义安装,需要勾选一下两项
Select “Custom” install and add the following packages:
·“Common Tools for Visual C++ 2015” under “Visual C++”
·“Tools (1.4.1) and Windows 10 SDK (10.0.14393)” under “Universal Windows App Development Tools”.

需要确认10.0.14393已经装好,不然后面的脚本会出错
方法:在这里能找到 C:\Program Files (x86)\Windows Kits\10\Include\10.0.14393.0

下载其他工具

4.1.2. Other tools and dependencies

Download and install following packages:

CMake
https:///files/v3.12/cmake-3.12.3-win64-x64.msi

用于安装 flex和bison的 cygwin
http:///setup-x86.exe (32bit) or
http:///setup-x86_64.exe (64bit)

OSGeo4W
http://download./osgeo4w/osgeo4w-setup-x86.exe (32bit) or http://download./osgeo4w/osgeo4w-setup-x86_64.exe (64bit)

ninja
https://github.com/ninja-build/ninja/releases/download/v1.7.2/ninja-win.zip

通过cygwin安装flex和bison

通过cygwin安装以下两个包,git完全可以不安装。

·bison
·flex
安装过程如下
打开后,install from Internet-> 按照默认路径,就在c:\cygwin64 下面,不要改,后面一直下一步

一定要选择版本,一般选择最新的版本就好了,选择好后先等等点下一步,然后继续搜索bison

之后再点击下一步,进入安装,时间有些长

通过OSGeo4W 安装依赖包

下面是通过OSGeo4W 来安装qgis的依赖包括qt,python等等一些列的包
在这里插入图片描述
第一步选择高级安装,下面都是默认的,特别是安装路径C:\OSGeo4W64不要修改,后面的脚本都是访问这个位置,修改了这个位置,后面的官方脚本也要改。同样的方法安装
qgis-dev-deps
官方给出的是这个qgis-rel-deps 我按照这个试了几次都不行,改为qgis-dev-deps才行,这一步很重要。之前这个坑踩得深啊,不过你们也能试试看,选择rel版本到底行不行。
这个是在线下载,耗时也不少,数据大概接近1G

复制ninja

ninja: copy ninja.exe to C:\OSGeo4W64\bin
把下载的ninja拷贝到 C:\OSGeo4W64\bin\

下载QGIS源码包

下面是下载QGIS的源码包,不需要通过git来下载,git下载的是没有压缩过的,数据大概有2G,也比较慢,直接到github上面下载你想要的版本,目前最新的是3.14.6
https://github.com/qgis/QGIS/tree/release-3_14
然后解压为qgis文件夹,放到C:\OSGeo4W64目录下

设置环境变量

下面就开始进入到批操作的环节了
在C:\OSGeo4W64下面,新建一个bat文件(文本文件改后缀名),

@echo off
call C:\OSGeo4W64\QGIS\ms-windows\osgeo4w\msvc-env.bat x86_64
@cmd

将以上内容复制进去,保存为 OSGeo4W-dev.bat
即此文在 C:\OSGeo4W64\OSGeo4W-dev.bat 这里

双击运行,这个是用于设置环境变量之类的,正常运行时不会报错的,有报错又要仔细看看报错内容。

通过命令行使用CMake 生成msvc的解决方案文件

下面开始通过命令行来cmake了
We will be using the file ms-windows/osgeo4w/configonly.bat to create an MSVC solution file。

 cd C:\OSGeo4W64\QGIS\ms-windows\osgeo4w

 configonly.bat

进入C:\OSGeo4W64\QGIS\ms-windows\osgeo4w目录,运行configonly.bat
这个过程极易出错,如果前面使用的是官方给的qgis-rel-deps,这边就报了很多错误,但是使用qgis-dev-deps,就没错误了。正常以上软件按照默认的安装位置安装,不会出错。如果出错,可能就是环境变量没有设置好,环境变量PATH里加入如下几个

应该就不会出现什么问题了。
如果一切正常,大概运行快3分钟,显示内容如下

C:\OSGeo4W64\qgis\ms-windows\osgeo4w>    configonly.bat
BEGIN: 2020/09/26 周六 21:13:00.60
CMAKE: 2020/09/26 周六 21:13:01.08
-- The C compiler identification is MSVC 19.0.24215.1
-- The CXX compiler identification is MSVC 19.0.24215.1
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/x86_amd64/cl.exe
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/x86_amd64/cl.exe -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done-- Detecting C compile features
-- Detecting C compile features - done-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/x86_amd64/cl.exe
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/x86_amd64/cl.exe -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done-- Detecting CXX compile features
-- Detecting CXX compile features - done-- QGIS version: 3.14.16 Pi (31416)-- Looking for CL_VERSION_2_2
-- Looking for CL_VERSION_2_2 - found
-- Found OpenCL: C:/OSGeo4W64/lib/opencl.lib (found version "2.2")-- Found OpenCL C++ headers: C:/OSGeo4W64/include
-- Found GRASS 7: C:/OSGEO4~2/apps/grass/grass78 (7.8.3, off_t size = 8)-- Found Proj: C:/OSGeo4W64/apps/proj-dev/lib/proj.lib version 7 (7.2.0)-- Found GEOS: C:/OSGeo4W64/lib/geos_c.lib (3.8.1)-- Found GDAL: C:/OSGeo4W64/apps/gdal-dev/lib/gdal_i.lib (3.2.0dev)-- Found Expat: C:/OSGeo4W64/lib/expat.lib
-- Found Spatialindex: C:/OSGeo4W64/lib/spatialindex-64.lib
-- Found Qwt: C:/OSGeo4W64/apps/Qt5/lib/qwt.lib (6.1.3)-- Found LibZip: C:/OSGeo4W64/lib/zip.lib
-- Found libzip: C:/OSGeo4W64/lib/zip.lib
-- Found Sqlite3: C:/OSGeo4W64/lib/sqlite3_i.lib
-- Found Protobuf: C:/OSGeo4W64/lib/libprotobuf.lib (found version "3.11.4")-- Found Protobuf: C:/OSGeo4W64/lib/libprotobuf.lib
-- Found ZLIB: C:/OSGeo4W64/lib/zlib.lib (found version "1.2.8")-- Found zlib: C:/OSGeo4W64/lib/zlib.lib
-- Found PostgreSQL: C:/OSGeo4W64/lib/libpq.lib
-- Found SpatiaLite: C:/OSGeo4W64/lib/spatialite_i.lib
-- Qt WebKit support enabled
-- Found Qt version: 5.11.2
-- Found QScintilla2: C:/OSGeo4W64/apps/Qt5/lib/qscintilla2.lib (2.10.8)-- Found QtKeychain: C:/OSGeo4W64/apps/Qt5/lib/qt5keychain.lib
-- Found QCA: C:\OSGEO4~2\apps\Qt5\lib\qca-qt5.lib (2.1.3)-- Pedantic compiler settings enabled
-- Debug output enabled
-- Found GSL: C:/OSGeo4W64/lib/gsl.lib;C:/OSGeo4W64/lib/cblas.lib
-- Found PythonInterp: C:/OSGeo4W64/bin/python3.exe (found suitable version "3.7", minimum required is "3")-- Found Python executable: C:/OSGeo4W64/bin/python3.exe
-- Found Python version: 3.7.0
-- Found Python library: C:/OSGeo4W64/apps/Python37/libs/python37.lib
-- Found Python site-packages: C:/OSGEO4~2/apps/Python37/Lib/site-packages
-- Found PyQt5 version: 5.11.3
-- Found SIP version: 4.19.14
-- Found QScintilla2 PyQt module: 2.10.8
-- Performing Test COMPILER_HAS_DEPRECATED_ATTR
-- Performing Test COMPILER_HAS_DEPRECATED_ATTR - Failed
-- Performing Test COMPILER_HAS_DEPRECATED
-- Performing Test COMPILER_HAS_DEPRECATED - Success
-- Found exiv2: C:/OSGeo4W64/lib/exiv2.lib
-- Found HDF5: hdf5::hdf5-shared (found version "1.10.4")-- Could NOT find PkgConfig (missing: PKG_CONFIG_EXECUTABLE)-- Found NetCDF: C:/OSGeo4W64/lib/netcdf.lib
-- Found LibXml2: C:/OSGeo4W64/lib/libxml2.lib (found version "2.9.1")-- Found OCI: C:/OSGeo4W64/lib/oci.lib
-- Found FCGI: C:/OSGeo4W64/lib/libfcgi.lib
-- Using PROJ >= 6 srs database.
-- Ctest Binary Directory set to: C:/OSGeo4W64/qgis/ms-windows/osgeo4w/build-qgis-test-x86_64/output/bin
-- Configuring done-- Generating doneCMake Warning:
  Manually-specified variables were not used by the project:

    CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS_NO_WARNINGS
    QT_HEADERS_DIR


-- Build files have been written to: C:/OSGeo4W64/qgis/ms-windows/osgeo4w/build-qgis-test-x86_64
Exiting after configuring build directory: C:\OSGeo4W64\qgis\ms-windows\osgeo4w\build-qgis-test-x86_64
FINISHED: 2020/09/26 周六 21:16:20.64

使用msvc来编译QGIS

下面开始使用msvc来编译
Compiling QGIS with MSVC:
We will need to run MSVC with all the environment variables set, thus we will run it as follows: Run the batch file OSGeo4W-dev.bat you created before. On the command prompt run

call gdal-dev-env.bat

to add the release gdal and proj libraries to your PATH. On the command prompt run

devenv

to open MSVC. From MSVC, open the solution file C:\OSGeo4W64\QGIS\ms-windows\osgeo4w\build-qgis-test-x86_64\qgis.sln. Try to build the solution (go grab a cup of tea, it may take a while). If it fails, run it again and again until there are (hopefully) no errors.

在命令行中首先运行之前的C:\OSGeo4W64\OSGeo4W-dev.bat ,然后接着输入 call gdal-dev-env.bat,这也是在设置环境变量。

然后在当前命令行中输入 devenv,打开msvc,然后从以下目录打开工程C:\OSGeo4W64\QGIS\ms-windows\osgeo4w\build-qgis-test-x86_64\qgis.sln

因为项目比较大,所以载入需要很长一段时间,里面大概有501个项目。

编译步骤比较重要,
编译顺序,qgis_core -> qgis_gui -> qgis_app -> qgis -> ALL_BUILD。
方法:选定一个项目,右键–>设置为活动项目,然后在右键–>生成

编译qgis_core 大约一个半小时,qgis_gui 大概一个多小时
剩下的大概也有一个半小时吧

编译完成后,所有生成的文件会在C:\OSGeo4W64\qgis\ms-windows\osgeo4w\build-qgis-test-x86_64\output\bin\RelWithDebInfo这个路径下面。
在这里插入图片描述

运行QGIS

如果想要在msvc外面运行QGIS,按照如下做法
在 C:\OSGeo4W64\qgis\ms-windows\osgeo4w\build-qgis-test-x86_64\output\bin\RelWithDebInfo 目录下新建一个文本文件,改名为 qgis_run.bat。使用记事本编辑,将下面的代码粘贴进去。

@echo off
call C:\OSGeo4W64\QGIS\ms-windows\osgeo4w\msvc-env.bat x86_64
call gdal-dev-env.bat
@cmd
start qgis.exe

双击 qgis_run.bat,在跳出来的命令行后再输入qgis.exe,即可打开。

调试QGIS

在msvc下调试时,先把qgis设置为活动项目(右键这个项目,选择设置为活动项目),然后点击 local windows debugger,或者菜单栏上Debug->start without Debugging。就能调试运行了。
在这里插入图片描述
注意:
如果想再次打开vs,调试qgis项目时,如果直接打开vs,在打开qgis项目是会出问题的,因为缺少相关环境变量的设置,会方便的办法是,新建一个bat文件,将环境变量的设置写进去,具体如下:
@echo off
call C:\OSGeo4W64\QGIS\ms-windows\osgeo4w\msvc-env.bat x86_64
@echo on
call gdal-dev-env.bat
start devenv

bat文件的内容如上,然后双击这个bat文件来打开vs,再打开qgis项目应该就没问题了

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多