0 前言
1. 编译环境&&软件版本:
(1)Ubuntu 22.04.4 LTS
需要准备一个全新的Linux环境,可以选择VMware虚拟机,虚拟机安装教程详见:八分钟完成VMware和ubuntu系统安装_哔哩哔哩_bilibilihttps://www.bilibili.com/video/BV1M94y1U7nc/?spm_id_from=333.880.my_history.page.click&vd_source=6697c5f80e9a8e0cbcc13d8d24b5b131
(2)QGIS-3.34 源码
源码从qgis官方GitHub上下载:GitHub - qgis/QGIS: QGIS is a free, open source, cross platform (lin/win/mac) geographical information system (GIS)QGIS is a free, open source, cross platform (lin/win/mac) geographical information system (GIS) - qgis/QGIShttps://github.com/qgis/QGIS 本文以ltr-3_34为例
(3)Clion 2024.1.4
Clion在Linux系统的安装和启动详见Linux下安装Clion_linux clion-CSDN博客https://blog.csdn.net/jkhihj/article/details/134424862
1 编译过程
1.1 打开Ubuntu终端,更新本地源数据库
sudo apt-get update
1.2 安装编译依赖
* 安装编译的依赖项要根据编译的qgis版本和Linux系统版本选择对应的安装命令,具体对应情况详见官方GitHub仓库:https://github.com/qgis/QGIS/blob/ltr-3_34/INSTALL.md 这里以Ubuntu 22.04.4 LTS(jammy)系统为例。
sudo apt-get install bison build-essential ca-certificates ccache cmake cmake-curses-gui dh-python doxygen expect flex flip gdal-bin git graphviz grass-dev libdraco-dev libexiv2-dev libexpat1-dev libfcgi-dev libgdal-dev libgeos-dev libgsl-dev libpdal-dev libpq-dev libproj-dev libprotobuf-dev libqca-qt5-2-dev libqca-qt5-2-plugins libqscintilla2-qt5-dev libqt5opengl5-dev libqt5serialport5-dev libqt5sql5-sqlite libqt5svg5-dev libqt5webkit5-dev libqt5xmlpatterns5-dev libqwt-qt5-dev libspatialindex-dev libspatialite-dev libsqlite3-dev libsqlite3-mod-spatialite libyaml-tiny-perl libzip-dev libzstd-dev lighttpd locales ninja-build ocl-icd-opencl-dev opencl-headers pandoc pdal pkg-config poppler-utils protobuf-compiler pyqt5-dev pyqt5-dev-tools pyqt5.qsci-dev python3-all-dev python3-autopep8 python3-dev python3-gdal python3-jinja2 python3-lxml python3-mock python3-nose2 python3-owslib python3-plotly python3-psycopg2 python3-pygments python3-pyproj python3-pyqt5 python3-pyqt5.qsci python3-pyqt5.qtmultimedia python3-pyqt5.qtpositioning python3-pyqt5.qtsql python3-pyqt5.qtsvg python3-pyqt5.qtwebkit python3-pyqtbuild python3-sip python3-termcolor python3-yaml qt3d-assimpsceneimport-plugin qt3d-defaultgeometryloader-plugin qt3d-gltfsceneio-plugin qt3d-scene2d-plugin qt3d5-dev qtbase5-dev qtbase5-private-dev qtkeychain-qt5-dev qtmultimedia5-dev qtpositioning5-dev qttools5-dev qttools5-dev-tools sip-tools spawn-fcgi xauth xfonts-100dpi xfonts-75dpi xfonts-base xfonts-scalable xvfb
1.3 设置ccache(可选,但是推荐)
cd /usr/local/bin
sudo ln -s /usr/bin/ccache gcc
sudo ln -s /usr/bin/ccache g++
1.4 准备开发环境
mkdir -p ${HOME}/dev/cpp
cd ${HOME}/dev/cpp
1.5 下载qgis源码
git clone https://github.com/qgis/QGIS.git
* 不推荐直接使用git命令拉取qgis源码,因为网络原因很容易造成下载中断,而且速度很慢。推荐在GitHub上直接下载完源码后复制到${HOME}/dev/cpp路径下。
* 下载解压工具
sudo apt-get install unzip
* 解压源码压缩包
unzip QGIS-ltr-3_34.zip
1.6 开始编译
(1)使用Clion打开qgis项目源码
(2)配置cmake
(3)修改cmake配置参数
修改以下参数,不编译qgis的test模块;指定qgis的安装路径,避免产生冲突;指定qgis编译工具。修改完以上参数后重新进行cmake配置。
cmake配置完成后结果如下:
(4)开始构建,点击在‘Debug’中全部构建
(5)在项目构建的过程中可能会与遇到以下问题:
Querying qmake about your Qt installation...
These bindings will be built: core.
Generating the core bindings...
sip-build: Unable to find file "QtXml/QtXmlmod.sip"
SIP无法定位到python的包,但先前我们已经把所有的依赖都安装好了,出现这个问题是Clion在进行cmake配置时,错误地配置了Python site-packages为/usr/local/lib/python3.10/dist-packages。
我们需要将/usr/lib/python3/dist-packages路径下的所有文件拷贝到/usr/local/lib/python3.10/dist-packages路径下,使用管理员权限执行以下命令:
sudo cp -r /usr/lib/python3/dist-packages /usr/local/lib/python3.10/
然后再次进行项目重构建,等待qgis构建完成。
(6)在构建的所有项目中选择qgis作为启动项,点击运行按钮,运行qgis。
成功启动qgis如图所示
至此,qgis在Linux之上编译成功!