文章目录
Windows下源码编译
1 目标
Windows下源码编译QGIS。
2 步骤
2.1 下载安装Visual Studio 2022
安装Visual Studio Community 2022即可记得选上C++环境。
2.2 下载安装CMake
下载安装 CMake 3.28.0
2.3 下载安装Cygwin
下载安装 最新版即可
需要安装
- flex
- bison
- git
2.4 下载安装OSGeo4W
下载安装 OSGeo4W
2.5 配置windows环境变量
2.6 批处理脚本
@echo off
set VS150COMNTOOLS=C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\Tools\
call "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvarsall.bat" x64
set INCLUDE=%INCLUDE%;C:\Program Files (x86)\Windows Kits\10\Include
set LIB=%LIB%;C:\Program Files (x86)\Windows Kits\10\Lib
set OSGEO4W_ROOT=C:\OSGeo4W
call "%OSGEO4W_ROOT%\bin\o4w_env.bat"
SET PYTHONHOME=%OSGEO4W_ROOT%\apps\Python312
SET PYTHONPATH=%PYTHONHOME%;%PYTHONHOME%\Scripts
set PYTHON_EXECUTABLE=%PYTHONHOME%/python3.exe
PATH %PYTHONPATH%;%PATH%
path %OSGEO4W_ROOT%\apps\Qt5\bin;%PATH%
set QT_PLUGIN_PATH=%OSGEO4W_ROOT%\apps\Qt5\plugins
set O4W_QT_PREFIX=%OSGEO4W_ROOT:\=/%/apps/Qt5
set O4W_QT_BINARIES=%OSGEO4W_ROOT:\=/%/apps/Qt5/bin
set O4W_QT_PLUGINS=%OSGEO4W_ROOT:\=/%/apps/Qt5/plugins
set O4W_QT_LIBRARIES=%OSGEO4W_ROOT:\=/%/apps/Qt5/lib
set O4W_QT_TRANSLATIONS=%OSGEO4W_ROOT:\=/%/apps/Qt5/translations
set O4W_QT_HEADERS=%OSGEO4W_ROOT:\=/%/apps/Qt5/include
set O4W_QT_DOC=%OSGEO4W_ROOT:\=/%/apps/Qt5/doc
set GDAL_INCLUDE_DIR = C:\OSGeo4W\apps\gdal-dev\include
set GDAL_LIBRARY = C:\OSGeo4W\apps\gdal-dev\lib\gdal_i.lib
set O4W_ROOT=%OSGEO4W_ROOT:\=/%
set LIB_DIR=%O4W_ROOT%
path %path%;C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.32.31326\bin\Hostx64\x64
path %PATH%;C:\OSGeo4W\apps\Qt5\bin;C:\cygwin64\bin
@set GRASS_PREFIX=C:\OSGeo4W\apps\grass\grass83
@set INCLUDE=%INCLUDE%;%OSGEO4W_ROOT%\include;C:\OSGeo4W\apps\gdal-dev\include
@set LIB=%LIB%;%OSGEO4W_ROOT%\lib;%OSGEO4W_ROOT%\lib;C:\OSGeo4W\apps\gdal-dev\lib
set LIB=%LIB%;%OSGEO4W_ROOT%\apps\Qt5\lib;%OSGEO4W_ROOT%\lib
set INCLUDE=%INCLUDE%;%OSGEO4W_ROOT%\apps\Qt5\include;%OSGEO4W_ROOT%\include
call "C:\CMake\bin\cmake-gui.exe"
2.7 运行脚本
使用管理员权限运行这个bat脚本,会自动打开cmake
先点击Configure,然后点击Generate即可(时间很长,按小时计)
2.8 使用vs2022 编译工程
经过漫长的等待,build目录下会生成工程文件,用vs2022打开编译。
成功编译后如下图所示
由于缺少dll,编译出来的不能运行,需要将
- C:\cygwin64\bin
- C:\OSGeo4W\bin
- C:\OSGeo4W\apps\gdal-dev\bin
- C:\OSGeo4W\apps\Qt5\bin
路径下所有dll文件,拷贝过来