ICode9

精准搜索请尝试: 精确搜索
首页 > 系统相关> 文章详细

在Ubuntu上编译QGIS 3.6.*-3.10.* 代码的填坑笔记

2020-06-02 10:06:05  阅读:385  来源: 互联网

标签:x86 lib QGIS dev 3.6 填坑 64 linux root


A . 系统环境

  • OS VER : Ubuntu 18.04.3 LTS
  • APT 源 : 采用阿里源
  • QGIS代码版本 : QGIS final-3.10.4

B. 系统更换【更新源】

提示:该步骤不是一定要操作的步骤,可跳过该步骤;但更换成阿里源后,采用apt-get安装软件会快很多!

1. 备份source.list

root@darling-G7:/etc/apt# cp /etc/apt/source.list /etc/apt/source.list.bak

2. 修改source.list

root@darling-G7:/etc/apt# gedit /etc/apt/source.list

执行如上命令,就会弹出一个文本编辑器;并把记事本中的所有内容替换成“阿里源”提供的内容,保存source.list内容即可关闭记事本。效果如下:

注意:

  • 因为系统是ubuntu 18.04 (bionic)版本,所以更新源也得用对应版本的;而ubuntu 20.04(focal)不能用于18.04版本!
  • 最好按照第一步保存source.list,以防万一去恢复
  • 记住这个bionic版本名,在QGIS的说明文档中也谈到了这个!

3. 更新本地的包清单(说白了就是让系统知道,根据source.list清单产生的缓存,以后去阿里源下载包)

root@darling-G7:/etc/apt# apt update

注意:

  • 在执行该命令的时候,如果遇到错误,可能会导致更新失败,请另行百度处理对应问题。
  • 更新的时候,要管理员权限!可用su root切换到管理用户。
  • ubuntu用户第一次不知道root账户,请用sudo passwd root进行修改密码。

C.  编译步骤(参考INSTALL

1. 安装构建依赖(Install build dependencies)

参看INSTALL文件的步骤,官网教我们安装依赖库;官方列出了5个发布版本的库,我这里用的Ubuntu 18.04 (bionic),对应的,也安装这个版本的依赖!选bionic、bionic、bionic,别选错了!!!强调强调!!!

如下贴出bionic版本安装依赖的命令:

apt-get install bison ca-certificates ccache cmake cmake-curses-gui dh-python doxygen expect flex gdal-bin git graphviz grass-dev libexiv2-dev libexpat1-dev libfcgi-dev libgdal-dev libgeos-dev libgsl-dev libpq-dev libproj-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 lighttpd locales ninja-build ocl-icd-opencl-dev opencl-headers pkg-config poppler-utils pyqt5-dev pyqt5-dev-tools pyqt5.qsci-dev python3-all-dev python3-dateutil python3-dev python3-future python3-gdal python3-httplib2 python3-jinja2 python3-lxml python3-markupsafe python3-mock python3-nose2 python3-owslib python3-plotly python3-psycopg2 python3-pygments python3-pyproj python3-pyqt5 python3-pyqt5.qsci python3-pyqt5.qtsql python3-pyqt5.qtsvg python3-pyqt5.qtwebkit python3-requests python3-sip python3-sip-dev python3-six python3-termcolor python3-tz python3-yaml qt3d-assimpsceneimport-plugin qt3d-defaultgeometryloader-plugin qt3d-gltfsceneio-plugin qt3d-scene2d-plugin qt3d5-dev qt5-default qt5keychain-dev qtbase5-dev qtbase5-private-dev qtpositioning5-dev qttools5-dev qttools5-dev-tools saga spawn-fcgi txt2tags xauth xfonts-100dpi xfonts-75dpi xfonts-base xfonts-scalable xvfb

2. 启动ccache(Optional, but recommended) (用于加快编译速度)(笔者跳过了这步)

cd /usr/local/bin
sudo ln -s /usr/bin/ccache gcc
sudo ln -s /usr/bin/ccache g++

这一步是可做,可不做的;我在没做之前,就看到这个目录下有gcc和g++,因为第1步用命令装了这2个东西;而且执行上面命令的时候,这2条创建软链的命令,根本就没有覆盖以前的链接文件。

就算你把这2个软链指向了ccache,编译前的配置阶段可能会出错,至于错误的原因这里先不探讨。所以笔者跳过了这步的操作。

3. 下载代码(Check out the QGIS Source Code)

参照官网说法,有如下2种检出代码的方式

1. Anonymous Checkout (没有提交权限,就用这种)

  cd ${HOME}/dev/cpp
  git clone git://github.com/qgis/QGIS.git

2. Developer Checkout  (有代码提交权限,就用这种)

  cd ${HOME}/dev/cpp
  git clone git@github.com:qgis/QGIS.git

对于官网提供的这2种方法,笔者为了方便,forked了官网的代码,直接检出自己的对应仓库;途中考虑到代码差不多1.8GB,懒得等,就花钱开了一台百M的服务器,在服务器上clone了,再打包下来,读者也可以参考。具体思路如下:

  • step1. 使用百兆服务器clone自己仓库中的QGIS代码(当然是为了方便后期提交代码);
  • step2. 使用tar 将目录打成tar包;
  • step3. 搭建nginx文件服务器
  • step4. 下载到本地机器(windows请用迅雷,Linux请用axel)

4. 开始编译(Starting the compile)

4.1 首先说明下我编译的规划(这一步中,请自行将QGIS的代码解压出来!)

  • 代码存放路径:/root/QGIS  (这里面看得到INSTALL说明文档)
  • makefile存放路径:/root/QGIS/build-master
  • 安装时的路径:/root/apps

4.2 创建对应目录

# 创建apps目录
root@darling-G7:/root# mkdir apps

# 创建build-master目录(将会用于执行ccmake)
root@darling-G7:/root/QGIS# mkdir build-master

4.3 使用ccmake生成makefile文件

root@darling-G7:/root/QGIS# cd build-master
# 下面的两个点表是上一级目录
root@darling-G7:/root/QGIS/build-master# ccmake ..
  • 当你运行了ccmake后(..是必须要写的),将会弹出1个菜单,你可以配置很多构建的参数:
  • 如果你想用于生成调试的程序,请设置CMAKE_BUILD_TYPE为Debug;
  • 如果你没有root权限,或者不想去覆盖掉已有的QGIS安装,请设置CMAKE_INSTALL_PREFIX,程序将安装到此目录;我通常用${HOME}/apps;
  • 配置好后,现在可以按c键去配置,按e去编辑参数改掉这些错误,按g可以生成makefile;
  • !提示,通常在按g之前,需要按c很多次,因为要处理掉一些参数错误(笔者没遇到错误)
  • 当按g生成完makefile后,就可以按q去退出ccmake交互式窗口了。
  • 正常执行完后,你会发现这个目录中有很多makefile文件

4.4 使用make命令开始编译

   注意make -jX,这里的X填写的是数字,表示编译时用几个核,越多越快,越快电脑越容易卡。

# 根据上一步生成的makefile,使用make命令编译代码
root@darling-G7:/root/QGIS/build-master# make -j4

# 编译完后你可以直接运行如下命令启动主程序
root@darling-G7:/root/QGIS/build-master# ./output/bin/qgis

# 若执行的时候,你发现动态链接库找不到;请参考问题清单的Q4、Q5;这里只简要说处理方法
# 用如下命令把生成的lib动态链接库,加入到环境变量
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/root/QGIS/build-master/output/lib/

# 使用make命令安装到系统中
# 这个命令会安装到/root/apps目录,这是由上一步生成makefile时,指定的CMAKE_INSTALL_PREFIX值
root@darling-G7:/root/QGIS/build-master# make install

当然,如果你已经熟悉了上面的4.3和4.4步骤,你也很清楚你想修改什么编译参数,那么你可以直接使用如下1条命令完成以上的2个操作:

cmake -D CMAKE_BUILD_TYPE=Debug -D CMAKE_INSTALL_PREFIX=${HOME}/apps ..

5. 加速编译(用ninja) 

For example, to configure your build you can do either one of:

  ccmake -G Ninja ..

  cmake -G Ninja -D CMAKE_BUILD_TYPE=Debug -D CMAKE_INSTALL_PREFIX=${HOME}/apps ..

Build and install with ninja:

  ninja (uses all cores by default; also supports the above described -jX option)
  ninja install

You can build just the targets you need using, for example:

  ninja qgis
  ninja pycore

D. Ubuntu下遇到的错误清单

Q1. Could NOT find Protobuf (missing: Protobuf_INCLUDE_DIR)

# 先安装缺失的依赖库
root@darling-G7:~# apt-get install libprotobuf-dev protobuf-compiler
# 检查是否安装成功
root@darling-G7:~# protoc --version
# 回显内容类似如下
libprotoc 2.6.1

Q2. Could not find exiv2

root@darling-G7:~# apt-get install exiv2 libexiv2-dev

Q3. 遇到安装某个包,大量依赖包无法自动装上(如下只是举例)

root@darling-G7:~# apt-get install libncurses5-dev Reading package lists… Done
Building dependency tree
Reading state information… Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
libncurses5-dev : Depends: libtinfo5 (= 5.9+20140913-1+deb8u3) but 6.0+20161126-1+deb9u2 is to be installed
Depends: libncurses5 (= 5.9+20140913-1+deb8u3) but 6.0+20161126-1+deb9u2 is to be installed
Depends: libtinfo-dev (= 5.9+20140913-1+deb8u3) but it is not going to be installed
Depends: ncurses-bin (= 5.9+20140913-1+deb8u3) but 6.0+20161126-1+deb9u2 is to be installed
E: Unable to correct problems, you have held broken packages.

处理方法:

  • 安装aptitude包管理器,然后使用该命令安装这个包;
root@darling-G7:~# apt-get install aptitude # 安装aptitude
root@darling-G7:~# aptitude install libncurses5-dev # 使用该命令安装指定包
  • 若aptitude也无法处理这个依赖问题,那就只能手动的去安装这些不能自动安装的包;
root@darling-G7:~# apt-get install <package-name> # 这里改为你缺失的包名

Q4. 关于查看指定二进制文件依赖哪些文件,请用ldd命令;此处有3个库not found。

root@darling-G7:~/build-master/output/bin# ldd qgis
	linux-vdso.so.1 (0x00007fff84d5f000)
	libqgis_app.so.3.13.0 => not found
	libqgis_gui.so.3.13.0 => not found
	libqgis_core.so.3.13.0 => not found
	libQt5Widgets.so.5 => /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5 (0x00007f70c3af3000)
	libQt5Gui.so.5 => /usr/lib/x86_64-linux-gnu/libQt5Gui.so.5 (0x00007f70c338a000)
	libQt5Core.so.5 => /usr/lib/x86_64-linux-gnu/libQt5Core.so.5 (0x00007f70c2c3f000)
	libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f70c28b6000)
	libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f70c269e000)
	libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f70c22ad000)
	libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f70c208e000)
	libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f70c1cf0000)
	libGL.so.1 => /usr/lib/x86_64-linux-gnu/libGL.so.1 (0x00007f70c1a64000)
	libpng16.so.16 => /usr/lib/x86_64-linux-gnu/libpng16.so.16 (0x00007f70c1832000)
	libharfbuzz.so.0 => /usr/lib/x86_64-linux-gnu/libharfbuzz.so.0 (0x00007f70c1594000)
	libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007f70c1377000)
	libicui18n.so.60 => /usr/lib/x86_64-linux-gnu/libicui18n.so.60 (0x00007f70c0ed6000)
	libicuuc.so.60 => /usr/lib/x86_64-linux-gnu/libicuuc.so.60 (0x00007f70c0b1e000)
	libdouble-conversion.so.1 => /usr/lib/x86_64-linux-gnu/libdouble-conversion.so.1 (0x00007f70c090d000)
	libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f70c0709000)
	libglib-2.0.so.0 => /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0 (0x00007f70c03f2000)
	/lib64/ld-linux-x86-64.so.2 (0x00007f70c45a6000)
	libGLX.so.0 => /usr/lib/x86_64-linux-gnu/libGLX.so.0 (0x00007f70c01c1000)
	libGLdispatch.so.0 => /usr/lib/x86_64-linux-gnu/libGLdispatch.so.0 (0x00007f70bff0b000)
	libfreetype.so.6 => /usr/lib/x86_64-linux-gnu/libfreetype.so.6 (0x00007f70bfc57000)
	libgraphite2.so.3 => /usr/lib/x86_64-linux-gnu/libgraphite2.so.3 (0x00007f70bfa2a000)
	libicudata.so.60 => /usr/lib/x86_64-linux-gnu/libicudata.so.60 (0x00007f70bde81000)
	libpcre.so.3 => /lib/x86_64-linux-gnu/libpcre.so.3 (0x00007f70bdc0f000)
	libX11.so.6 => /usr/lib/x86_64-linux-gnu/libX11.so.6 (0x00007f70bd8d7000)
	libxcb.so.1 => /usr/lib/x86_64-linux-gnu/libxcb.so.1 (0x00007f70bd6af000)
	libXau.so.6 => /usr/lib/x86_64-linux-gnu/libXau.so.6 (0x00007f70bd4ab000)
	libXdmcp.so.6 => /usr/lib/x86_64-linux-gnu/libXdmcp.so.6 (0x00007f70bd2a5000)
	libbsd.so.0 => /lib/x86_64-linux-gnu/libbsd.so.0 (0x00007f70bd090000)
	librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f70bce88000)

Q5. libqgis_app.so.3.13.0 => not found 等问题(承接上一个问题)

若执行后提示,找不到某个*.so.*文件,如libqgis_app.so.3.13.0; 可使用locate进行定位。

root@darling-G7:~/build-master/output/bin# locate libqgis_app.so.3.13.0
/root/build-master/output/lib/libqgis_app.so.3.13.0

这说明本系统中有该动态链接库,只是当前程序找不到该库;笔者思考了下,是因为这个库文件不在环境变量中,所以程序找不到;为了解决这个问题,你的控制台需要执行如下命令

# 临时地把qgis编译生成的库文件,加到动态链接库的变量中
# 你生成的动态链接库目录路径不同,注意更改!
root@darling-G7:~/build-master# export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/root/build-master/output/lib/

 

 

 

标签:x86,lib,QGIS,dev,3.6,填坑,64,linux,root
来源: https://blog.csdn.net/DanyelleG/article/details/106454423

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有