I am trying to build/install Mapnik (3.0.10) on a CentOS 7 system and I am having trouble getting all the dependencies in place and recognized.

I have installed gcc/g++ compiler from the gcc6 series to ensure c++14 support, which Mapnik needs. If I point directly to my new gcc and poll its version I get this:

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

Next I temporarily overrode the $CC and $CXX environment variables so the updated compiler would be used for subsequent builds, then I installed Boost 1.69.0 from source, like this. Note that this actually installs a second Boost, so the --prefix parameter establishes where this alternative Boost will install to:

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

Now, if I check /opt/boost, I see what I expect..

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

Finally I get to installing Mapnik itself. I'm basically using the approach noted here. However, I've already got several of the dependencies in place due to previously installing GDAL and PostGIS. But, when I run Mapnik's .configure step, it fails to find my optional dependencies.

For example, I built proj from source and know exactly where it is..

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

And ldconfig finds it too..

[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

So I specify my alternative Boost location as well as PROJ_LIBS and PROJ_INCLUDES as .configure parameters.....but it still fails to find proj? Here's some abridged output. Note that it finds my Boost, as specified, but it fails to find proj, in spite of the config params..

[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
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
Checking for C library proj... no
Could not find optional header or shared library for proj

Most of the optional dependencies seem to be similarly overlooked—libpng-devel, libjpeg-devel, sqlite3, the tiff stuff, proj, etc. And most of those are package installs, not source builds.

As we'll be using this server for quite some time I would like to have the latest Mapnik with its full complement of support (especially for proj, png, and jpeg). It's especially vexing that my proj install isn't tying in, because I know exactly where it is and provided Mapnik those parameters.

I apologize for the long noisy read, but does anyone see what I am missing?

[Update: 4.24.19 5pm]

Ok, I may have figured it out. I was hoping it had something to do with environment/shell setup, rather than having to build all dependencies from source with the same compiler, and stumbled onto an old post where a "Dom Lehr" recommended modifying the LD_LIBRARY_PATH environment variable to include specifically /usr/local/lib. Well, I tried that, and it didn't solve the problem. However, I optimistically expanded the parameter values to include some additional locations, and now I can complete the .configure step with all dependencies recognized. Here's how I did it..

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:

I added everything I could think of where I found seemingly related .so files. Save the file, then..


Then I logged out of my terminal session and logged back in to refresh the shell. Then double-checked that it worked:

[root@raven mapnik-v3.0.10]# echo $LD_LIBRARY_PATH

It did. So I refreshed my temporary compiler arguments, went to the Mapnik source folder, and re-ran the .configure instruction, and it worked without issue..

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

And it worked. Now, whether it will build without issue is still a mystery, but this seems to have done the trick!

Well I spoke to soon. Now make fails with..

<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

....which is in-line with a lot of others posts I've found where folks are having trouble with mismatched compiler/dependency issues. Back to the drawing board.


I finally got everything working after a few departures and fresh starts. But I don't know if they were all ultimately necessary, or if one special adjustment righted the ship.

If there was a single solution, it might be that I switched from building mapnik-v3.0.10, downloaded from AWS S3, to mapnik-v3.0.22, which is referenced on the Mapnik homepage as the latest stable release and downloaded directly from github.

Anyway here's what worked for me from start to finish:

Add alternate gcc/g++ compiler

Installed gcc/g++ compiler from the gcc6 series in an alternate directory to ensure c++14 support. It has to be referenced directly from /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
./configure --disable-multilib --enable-languages=c,c++
make -j 4
make install

Delete and rebuild alternate Boost

Deleted my /opt/boost directory from my earlier build and rebuilt Boost with different compiler flags as demonstrated in this script. Like gcc/g++ above, this Boost installs alongside the system's default and you'll find it wherever you assigned it with the --prefix parameter, in my case, /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

Weird adjustment to Boost includes file

On account of a weird compile 'gotcha!' associated with Boost >= 1.64, make a slight modification to a file in the Boost includes path, matrix_transformers.hpp, as suggested by Artem here:

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

i Toggle INSERT mode..

## 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! Save changes..

[Update 6.18.2019] Sometime later I ran into a dependency mismatch and the solution was to build libpng from source, then point my Mapnik config script at the new libpng.

On my system, I needed to remove the old libpng first, but yum was going to remove a bunch of other dependencies too. I was able to remove only libpng and side-step other dependency removals by executing both of these instructions.

WARNING: Working around the package manager is a risk!

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

Build libpng from source

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 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

You can confirm it's present by executing.. libpng-config --version

Fix the shell environment

We need to establish a few things in the system environment before proceeding with the Mapnik installation.

Set local lib path..

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

i Toggle INSERT mode..

## Add this line:

ESC:x! Save changes..

Set the LD_LIBRARY_PATH value. I'm not sure if this is the most appropriate way to set this variable, but this is what I did.

vi /etc/profile.d/sh.local

i Toggle INSERT mode..

## 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! Save changes..

Add our alternative Boost location to the environment. It occurs to me that it's possible this could create ambiguity conflicts with the default Boost installation, but it seems to have worked in my case. Since we specify Boost libs/includes in the Mapnik config, this may not be necessary.

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 Toggle INSERT mode..


ESC:x! Save changes..


Install various Mapnik dependencies and build Mapnik from source

Note: I just plucked these install commands from the script already linked above. However, I added harfbuzz-devel as it seems to have been missing. But if you've installed things like GDAL and PostGRESql/PostGIS, you likely have several of these installed already. So look through the list and remove anything that doesn't jive with your environment.

# 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 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

If you want to test your install, cd into the Mapnik source's demo directory and check out the c++ and/or the python examples. Note the README files in those folders, as I think you have to build the c++ demo before you can test it, but you can use the Python one pretty easily, just execute..

python rundemo.py

..and some images should be rendered in that directory.

Another gotcha. If you've installed Mapnik previously, you may notice the Python demo images do note have feature labels! This is not a problem with your system, they actually are not presently supported for Mapnik 3 python bindings. Apparently XML-formatted style declarations work fine, though, so as long as you use external style sheets, like with TileStache for example, you shouldn't be affected. But, if you need the python bindings for your use case, you may want to consider installing Mapnik 2 in a custom directory alongside Mapnik 3.

At this point, after a lot of googling and reading threads and trying different things, my install seems to be working. So hopefully this exploration helps someone else struggling with their Cent OS install.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.