CentOS 7:构建 Mapnik 时,配置步骤找不到 libpng-devel、libjpeg-devel 等可选依赖项

CentOS 7:构建 Mapnik 时,配置步骤找不到 libpng-devel、libjpeg-devel 等可选依赖项

我正在尝试在 CentOS 7 系统上构建/安装 Mapnik (3.0.10),但在获取所有依赖项并进行识别时遇到困难。

我已经安装了 gcc6 系列的 gcc/g++ 编译器,以确保 Mapnik 需要的 c++14 支持。如果我直接指向我的新版本gcc并轮询其版本,我会得到以下结果:

[root@raven ~]# /usr/local/bin/gcc --version
gcc (GCC) 6.5.0
Copyright (C) 2017 Free Software Foundat/..snip..

接下来,我暂时覆盖$CC$CXX环境变量,以便更新的编译器将用于后续构建,然后我从源代码安装了 Boost 1.69.0,如下所示。请注意,这实际上会安装第二个 Boost,因此该--prefix参数确定了此替代 Boost 将安装到的位置:

export CC=/usr/local/bin/gcc
export CXX=/usr/local/bin/g++

cd /root/downloads
wget https://dl.bintray.com/boostorg/release/1.69.0/source/boost_1_69_0.tar.gz
tar -xzf boost_1_*
cd boost_1_*
./bootstrap.sh --prefix=/opt/boost
./b2 install --prefix=/opt/boost --with=all

现在,如果我检查/opt/boost,我会看到我所期望的..

[root@raven ~]# dir /opt/boost/
include  lib

最后我开始安装 Mapnik 本身。我基本上在使用这里提到的方法。但是,由于之前安装了 GDAL 和 PostGIS,我已经获得了一些依赖项。但是,当我运行 Mapnik 的.configure步骤时,它无法找到我的可选依赖项。

例如,我proj从源代码构建并确切地知道它在哪里。

[root@raven ~]# dir /usr/proj49/
bin  include  lib  share

而且ldconfig也找到了..

[root@raven mapnik-v3.0.10]# ldconfig -p | grep libproj
        libproj.so.12 (libc6,x86-64) => /usr/proj49/lib/libproj.so.12
        libproj.so.0 (libc6,x86-64) => /lib64/libproj.so.0
        libproj.so (libc6,x86-64) => /usr/proj49/lib/libproj.so
        libproj.so (libc6,x86-64) => /lib64/libproj.so

所以我指定了我的替代Boost位置以及PROJ_LIBS参数......但它仍然找不到?这是一些删节的输出。请注意,它按照指定找到了我的 Boost,但尽管有配置参数,但它无法找到 ..PROJ_INCLUDES.configureprojproj

[root@raven ~]# cd /root/downloads/mapnik-v3.0.10
[root@raven mapnik-v3.0.10]# ./configure BOOST_LIBS=/opt/boost/lib BOOST_INCLUDES=/opt/boost/includes PROJ_LIBS=/usr/proj49/lib PROJ_INCLUDES=/usr/proj49/include
..snip..
Searching for boost libs and headers... (cached)
Found boost libs: /opt/boost/lib
Found boost headers: /opt/boost/include
Checking for C++ header file boost/version.hpp... yes
Checking for Boost version >= 1.47... yes
Found boost lib version... 1_69
..snip..
Checking for C library proj... no
Could not find optional header or shared library for proj
..snip..

大多数可选依赖项似乎同样被忽视libpng-devel——、、libjpeg-develsqlite3、tiff 东西、proj 等。其中大多数是包安装,而不是源构建。

由于我们将使用该服务器相当长一段时间,我希望拥有最新的 Mapnik 及其完整的支持(特别是对 proj、png 和 jpeg)。特别令人烦恼的是我的proj安装没有绑定,因为我确切地知道它在哪里并向 Mapnik 提供了这些参数。

对于冗长的阅读,我深表歉意,但是有人看到我错过了什么吗?

[更新: 4.24.19 5pm]

好吧,我可能已经弄清楚了。我希望它与环境/shell 设置有关,而不是必须使用相同的编译器从源代码构建所有依赖项,并偶然发现了一个旧帖子其中“Dom Lehr”建议修改LD_LIBRARY_PATH环境变量以专门包含/usr/local/lib.嗯,我尝试了一下,并没有解决问题。但是,我乐观地扩展了参数值以包含一些其他位置,现在我可以.configure在识别所有依赖项的情况下完成该步骤。我是这样做的..

vi /etc/profile.d/sh.local
# Add colon-separated paths to the LD_LIBRARY_PATH variable like this..
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib:/usr/local/lib64:/usr/lib:/usr/lib64:

我在发现看似相关的 .so 文件的地方添加了我能想到的所有内容。保存文件,然后..

/sbin/ldconfig
ldconfig

然后我退出终端会话并重新登录以刷新 shell。然后仔细检查它是否有效:

[root@raven mapnik-v3.0.10]# echo $LD_LIBRARY_PATH
/opt/remi/php70/root/usr/lib64::/usr/local/lib:/usr/local/lib64:/usr/lib:/usr/lib64:

它做了。因此,我刷新了临时编译器参数,转到 Mapnik 源文件夹,然后重新运行指令.configure,它工作正常,没有问题。

export CC=/usr/local/bin/gcc
export CXX=/usr/local/bin/g++
cd /root/downloads/mapnik-v3.0.10
./configure BOOST_LIBS=/opt/boost/lib BOOST_INCLUDES=/opt/boost/includes

它奏效了。现在,它是否能够顺利构建仍然是一个谜,但这似乎已经成功了!

好吧,我很快就谈到了。现在make失败了..

<mapnik::geometry::geometry_collection<double> > >&&’
scons: *** [src/json/mapnik_json_geometry_grammar.o] Error 1
scons: building terminated because of errors.
make: *** [src/json/libmapnik-json.a] Error 2

....这与我发现的许多其他帖子一致,人们在这些帖子中遇到了不匹配的编译器/依赖项问题。回到绘图板。

答案1

经过几次离开和新的开始后,我终于让一切正常运转。但我不知道它们最终是否都是必要的,或者是否有一项特殊的调整使船恢复正常。

如果有一个解决方案,那就是可能mapnik-v3.0.10从从 AWS S3 下载的构建切换到了mapnik-v3.0.22,它在 Mapnik 主页上被引用为最新的稳定版本并直接从 github 下载。

不管怎样,这就是从开始到结束对我有用的东西:

添加备用 gcc/g++ 编译器

在备用目录中安装了 gcc6 系列的 gcc/g++ 编译器,以确保 c++14 支持。它必须直接从 引用/usr/local/bin

yum -y install bzip2
cd /root/downloads
screen -U -S gcc
wget http://ftp.mirrorservice.org/sites/sourceware.org/pub/gcc/releases/gcc-6.5.0/gcc-6.5.0.tar.gz
tar zxf gcc-6.5.0.tar.gz
cd gcc-6.5.0
./contrib/download_prerequisites
./configure --disable-multilib --enable-languages=c,c++
make -j 4
make install

删除并重建备用 Boost

从我之前的构建中删除了我的/opt/boost目录,并使用不同的编译器标志重建了 Boost,如所示这个脚本。与上面的 gcc/g++ 一样,此 Boost 与系统默认值一起安装,无论您在何处使用参数--prefix(在我的例子中为/opt/boost.

cd /opt
rm -rf boost
cd /root/downloads
export CC=/usr/local/bin/gcc
export CXX=/usr/local/bin/g++
JOBS=`grep -c ^processor /proc/cpuinfo`
./bootstrap.sh --prefix=/opt/boost
./b2 --prefix=/opt/boost -d1 -j${JOBS} --with-thread --with-filesystem --with-python --with-regex -sHAVE_ICU=1 --with-program_options --with-system link=shared release toolset=gcc stage
./b2 --prefix=/opt/boost -j${JOBS} --with-thread --with-filesystem --with-python --with-regex -sHAVE_ICU=1 --with-program_options --with-system toolset=gcc link=shared release install

对 Boost 包含文件的奇怪调整

由于奇怪的编译“陷阱!”与Boost >= 1.64相关,对Boost包含路径中的文件进行轻微修改matrix_transformers.hpp,,正如 Artem 在这里建议的那样:

vi /opt/boost/include/boost/geometry/strategies/transform/matrix_transformers.hpp

i切换插入模式..

## Change the order of these three lines, near the top of the file..
## ..snip..
#include <cstddef>

#include <boost/qvm/mat_operations.hpp>    <-- This one has to be moved from the bottom of this group, to the top.
#include <boost/qvm/mat.hpp>
#include <boost/qvm/mat_access.hpp>
## ..snip..

ESC:x!保存更改..


[更新 6.18.2019] 过了一段时间我遇到依赖不匹配解决方案是libpng从源代码构建,然后将我的 Mapnik 配置脚本指向新的libpng.

在我的系统上,我需要libpng先删除旧的,但yum要删除一个其他依赖项也是如此。通过执行这两条指令,我能够仅删除libpng并回避其他依赖项删除。

警告:使用包管理器工作是有风险的!

rpm -e --nodeps libpng
rpm -e --nodeps libpng-devel

从源代码构建 libpng

cd /root/downloads
mkdir libpng1616-src
cd libpng1616-src
wget http://downloads.sourceforge.net/libpng/libpng-1.6.16.tar.xz
tar -xf libpng-1.6.16.tar.xz
cd libpng-1.6.16
./configure --prefix=/usr --disable-static &&
make
make check
make install &&
mkdir -v /usr/share/doc/libpng-1.6.16 &&
cp -v README libpng-manual.txt /usr/share/doc/libpng-1.6.16

您可以通过执行来确认它是否存在。 libpng-config --version


修复 shell 环境

在继续安装 Mapnik 之前,我们需要在系统环境中建立一些东西。


设置本地库路径..

cd /etc/ld.so.conf.d/
touch root-local-lib-path.conf
vi /etc/ld.so.conf.d/root-local-lib-path.conf

i切换插入模式..

## Add this line:
/usr/local/lib

ESC:x!保存更改..


设置LD_LIBRARY_PATH值。我不确定这是否是设置此变量的最合适方法,但这就是我所做的。

vi /etc/profile.d/sh.local

i切换插入模式..

## Add these lines, or the equivalent for your system customizations:
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib:/usr/local/lib64:/usr/lib:/usr/lib64:

## Update 6.18.2019: I later added these two environment vars.
## If you haven't already installed gdal or proj4 (below) it would be better to install them first, then return to this file and add them later.
## Finally make sure these paths are correct for your installation!
export GDAL_DATA=/usr/share/gdal
export PROJ_LIB=/usr/share/proj

ESC:x!保存更改..


将我们的替代 Boost 位置添加到环境中。我觉得这可能会与默认的 Boost 安装产生歧义冲突,但它似乎在我的情况下有效。由于我们在 Mapnik 配置中指定了 Boost libs/includes,因此这可能不是必需的。

cd /etc/ld.so.conf.d
touch boost-1.69.0-libs.conf
vi /etc/ld.so.conf.d/boost-1.69.0-libs.conf

i切换插入模式..

/opt/boost/lib

ESC:x!保存更改..

ldconfig

安装各种 Mapnik 依赖项并从源代码构建 Mapnik

注意:我刚刚从以下位置提取了这些安装命令上面已经链接的脚本。但是,我添加了它,harfbuzz-devel因为它似乎丢失了。但如果您已经安装了 GDAL 和 PostGRESql/PostGIS 之类的东西,那么您可能已经安装了其中的几个。因此,请仔细查看列表并删除任何与您的环境不相符的内容。

# You might need epel packages for some of these dependencies..
yum install epel-release

# Primary dependencies..
yum -y install make gcc47 gcc-c++ bzip2-devel harfbuzz-devel libpng-devel libtiff-devel zlib-devel libjpeg-devel libxml2-devel python-setuptools git-all python-nose python-devel python proj-devel proj proj-epsg proj-nad freetype-devel freetype libicu-devel libicu git bzip2

# Optional dependencies..
yum -y install gdal-devel gdal postgresql-devel sqlite-devel sqlite libcurl-devel libcurl cairo-devel cairo pycairo-devel pycairo postgresql93 postgresql93-server postgresql93-libs postgresql93-contrib postgresql93-devel postgis2_93 vim

# Ensure the alternate, updated gcc/g++ compiler is still referenced in the environment!
export CC=/usr/local/bin/gcc
export CXX=/usr/local/bin/g++

# Get the source and install Mapnik
cd /root/downloads
wget https://github.com/mapnik/mapnik/releases/download/v3.0.22/mapnik-v3.0.22.tar.bz2
tar -xf ./mapnik-v3.0.22.tar.bz2
cd mapnik-v3.0.22
# Update 6.18.2019: Per the libpng issue I had I eventually rebuilt Mapnik using more configuration parameters, specifically assignments for PROJ, GDAL, as well as PNG.
./configure BOOST_LIBS=/opt/boost/lib BOOST_INCLUDES=/opt/boost/includes PROJ_LIB=/usr/proj49/lib PROJ_INCLUDES=/usr/proj49/include GDAL_LIBS=/usr/lib64 GDAL_INCLUDES=/usr/include/gdal PNG_LIBS=/usr/lib PNG_INCLUDES=/usr/include/libpng16
make
make test ## Mine had a few errors, but I ignored them.. :/
make install

# And install python bindings if you want
yum install python-pip
yum install python-wheel
pip install mapnik

如果您想测试安装,cd请进入 Mapnik 源代码的演示目录并查看 c++ 和/或 python 示例。请注意README这些文件夹中的文件,因为我认为您必须先构建 c++ 演示才能测试它,但您可以非常轻松地使用 Python,只需执行..

python rundemo.py

..并且一些图像应该在该目录中呈现。

另一个问题。如果您之前安装过 Mapnik,您可能会注意到 Python 演示图像确实有功能标签!这不是您的系统的问题,实际上是目前不支持 Mapnik 3 python 绑定。不过,显然 XML 格式的样式声明工作得很好,因此只要您使用外部样式表(例如 TileStache),您就不会受到影响。但是,如果您的用例需要 python 绑定,您可能需要考虑将 Mapnik 2 与 Mapnik 3 一起安装在自定义目录中。

此时,经过大量谷歌搜索和阅读线程并尝试不同的事情后,我的安装似乎正在运行。因此,希望这次探索能够帮助那些在安装 Cent 操作系统时遇到困难的人。

相关内容