Compile mapnik on Rocky9

If anyone here has been able to successfully compile maknik on Rocky9 could you please share your process for doing so, or point me in the direction of suitable instructions. I need to compile it as, for reasons nobody seams to understand, they have removed PROJ4 from the available pre-built packages. Right now I have a database of contour information that can no longer be used with OSM maps because of this change and the original SRTM source data is no longer available, preventing me from switching to a different projection.

These instructions seem to be pretty clear: mapnik/INSTALL.md at master · mapnik/mapnik · GitHub I would expect once you have installed the dependencies prior to configure, make, make install commands it should work fine.

Yes, those instruction do appear to be clear enough but, despite meeting the listed dependencies, it will not compile on Rocky9. I’ve spent several days already on this with little progress, hence the question I posted.

Let me see if I can do it on my Rocky 9 VM and perhaps give something more specific.

Dependency Installation

The first command installs the entire group of Development Tools. The second command installs the dependencies required by Mapnik. Some of them were already installed by the use of the first command, however, I have listed them for completeness:

dnf group install "Development Tools"
dnf install -y python3-scons boost-devel libicu-devel zlib-devel freetype-devel libxml2-devel harfbuzz-devel libpng-devel libjpeg-turbo-devel libtiff-devel libwebp-devel proj-devel cairo-devel pkgconf-pkg-config libpq-devel gdal-devel sqlite-devel

some of those dependencies in the second command are optional, as shown in the link I provided earlier (review the documentation to check/verify what is required and what is optional), so you can decide whether you want them or not, or just install anyway and build a fully complete version of Mapnik. I’ve included every single dependency, since I do not know what your requirements are (other than needing proj).

Clone and prep the Mapnik repository

The first git command clones the repository, then the second git command installs the submodules that are required for Mapnik:

git clone https://github.com/mapnik/mapnik
cd mapnik
git submodule update --init

Build Mapnik

Then we build/compile Mapnik using the commands below:

./configure
make
make test
make install

you do not need to use the make test command if you do not wish, I have just included it for completeness (as it was mentioned in the documentation link I sent earlier and is usually a good command to use prior to make install to ensure that everything did actually work, rather than just install and find it’s incomplete).

My configure output shows that all dependencies were installed/met:

root@rocky9:/git/mapnik# ./configure
scons: Reading SConscript files ...

Welcome to Mapnik...

Configuring build environment...
Configuring on Linux in *release mode*...
C++ compiler: c++ (GCC) 11.4.1 20231218 (Red Hat 11.4.1-3)
Copyright (C) 2021 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Checking for pkg-config... yes
Checking for freetype2... yes
Checking for dlfcn.h support ... yes
Checking if compiler (c++) supports -std=c++17 flag... yes
Checking for C library z... yes
Checking for C++ library icuuc... yes
Checking for ICU version >= 4.0... yes (found ICU 67.1)
Checking for C++ library harfbuzz... yes
Checking for HarfBuzz version >= 0.9.34... yes (found HarfBuzz 2.7.4)
Checking for HarfBuzz with freetype support... yes
Searching for boost libs and headers... (cached)
Using default boost lib dir: /usr/lib
Using default boost include dir: /usr/include
Checking for C++ header file boost/version.hpp... yes
Checking for Boost version >= 1.73... yes
Found boost lib version... 1_75
Checking for C++ library boost_regex... yes
Checking for C++ library boost_program_options... yes
Checking whether Boost was compiled with C++11 scoped enums ... no
Checking if boost_regex was built with ICU unicode support... yes
Checking for C library jpeg... yes
Checking for C library proj... yes
Checking for Proj version >=7.2.0...yes (found Proj 8.2.0)
Checking for C library png... yes
Checking for C library webp... yes
Checking for C library tiff... yes
Checking for PROJ_LIB directory...(cached) `pkg-config proj --variable=datadir` returned:
/usr/share/proj
Checking for ICU data directory...icu-config returned /usr/share/icu/67.1
Checking for GDAL data directory... gdal-config returned /usr/share/gdal
Checking for requested plugins dependencies...
Checking for pg_config... yes
Checking for pg_config... yes
Checking for gdal-config --libs... yes
Checking for gdal-config --cflags... yes
Checking for name of gdal library... gdal
Checking for C++ library gdal... yes
Checking if gdal is ogr enabled... yes
Checking for gdal-config --libs... yes
Checking for gdal-config --cflags... yes
Checking for name of ogr library... gdal
Checking for C++ library gdal... yes
Checking for C library sqlite3... yes
Checking if SQLite supports RTREE... yes
Checking for cairo... yes
Checking for cairo lib and include paths... yes
Checking for cairo freetype font support ... yes

All Required dependencies found!

Saving new file 'config.py'...
Will hold custom path variables from commandline and python config file(s)...

Configure completed: run `make` to build or `make install`

I’ve not included the make output because that is simply just huge. And yes, I also realise compiling as root is not a good idea, but this is just a test system so it’s not really that important for me. That said, the process above should still work for compiling as a regular user.

root@rocky9:/git/mapnik# mapnik-config --help
Usage: mapnik-config [OPTION]

Known values for OPTION are:

  -h --help         display this help and exit
  -v --version      version information (MAPNIK_VERSION_STRING)
  --version-number  version number (MAPNIK_VERSION) (new in 2.2.0)
  --git-revision    git hash from "git rev-list --max-count=1 HEAD"
  --git-describe    git decribe output (new in 2.2.0)
  --fonts           default fonts directory
  --input-plugins   default input plugins directory
  --defines         pre-processor defines for Mapnik build (new in 2.2.0)
  --prefix          Mapnik prefix [default /usr/local]
  --lib-name        Mapnik library name
  --libs            library linking information
  --dep-libs        library linking information for Mapnik dependencies
  --ldflags         library paths (-L) information
  --includes        include paths (-I) for Mapnik headers (new in 2.2.0)
  --dep-includes    include paths (-I) for Mapnik dependencies (new in 2.2.0)
  --cxxflags        c++ compiler flags and pre-processor defines (new in 2.2.0)
  --cflags          all include paths, compiler flags, and pre-processor defines (for back-compatibility)
  --cxx             c++ compiler used to build mapnik (new in 2.2.0)
  --all-flags       all compile and link flags (new in 2.2.0)
  --gdal-data       path to GDAL_DATA directory, if detected at build time (new in 3.0.16)
  --proj-lib        path to PROJ_LIB directory, if detected at build time (new in 3.0.16)
  --icu-data        path to ICU_DATA directory, if detected at build time (new in 3.0.16)

To use mapnik-index and mapnik-render:

export LD_LIBRARY_PATH=/usr/local/lib

and then run either of the aforementioned commands, eg:

root@rocky9:/usr/local/bin# export LD_LIBRARY_PATH=/usr/local/lib

root@rocky9:/usr/local/bin# mapnik-index --help
Mapnik CSV/GeoJSON index utility:
  -h [ --help ]               Produce usage message
  -V [ --version ]            Print version string
  -v [ --verbose ]            Verbose output
  -d [ --depth ] arg          Max tree depth
                              (default 8)
  -r [ --ratio ] arg          Split ratio (default 0.55)
  -s [ --separator ] arg      CSV columns separator
  -q [ --quote ] arg          CSV columns quote
  -H [ --manual-headers ] arg CSV manual headers string
  --files arg                 Files to index: file1 file2 ...fileN
  --validate-features         Validate GeoJSON features
  -b [ --bbox ] arg           Only index features within bounding box: 
                              --bbox=minx,miny,maxx,maxy

root@rocky9:/usr/local/bin# mapnik-render --help
mapnik-render utility:
  -h [ --help ]         produce usage message
  -V [ --version ]      print version string
  -v [ --verbose ]      verbose output
  --open                automatically open the file after rendering
  --xml arg             xml map to read
  --img arg             image to render
  --scale-factor arg    scale factor for rendering
  --map-width arg       map width in pixels
  --map-height arg      map height in pixels
  --variables           make map parameters available as render-time variables
  --bbox arg            bounding box  e.g <minx,miny,maxx,maxy> in Map's SRS
  -g [ --geographic ]   bounding box is in WGS 84 lon/lat
  --plugins-dir arg     directory containing input plug-ins (default: 
                        ./plugins/input)
  --fonts-dir arg       directory containing fonts (default: relative to 
                        <plugins-dir> or ./fonts if no <plugins-dir> specified)

If it still doesn’t work for you, then you will have to post a lot more information, especially any errors during the compilation process. Since you didn’t mention anything previously it would most likely suggest you were missing dependencies or something.

However, at that point, you should be asking Mapnik about the compile errors since it is related to their program and not a Rocky Linux problem. You should be able to open issues on the Mapnik Github project and post the errors/problems there with the compile process.

1 Like

Thank you very much for going to that much trouble, although it leaves me puzzled. I went through those steps and my ./config completed without problems but when I tried to make it kept complaining about missing dependencies. In particular, it wasn’t finding my header files, because it wasn’t looking in the right places.

I’ll create a VM and start from scratch, which I really should have tried that before asking for help. If I match your results I’ll just copy everything over from there. If not, I might just try to copy mapnik from my old CentOS 7 drive, which I had forgotten I kept when upgrading the server.

Either way, thank you very much.

It would suggest that the *-devel packages for the dependencies were missing. For example there are zlib and zlib-devel packages, the devel ones will pull in what is required for compiling. The main zlib is just the library which is what would normally be used on a system for every day use. At least that is all that comes to mind right now. The binaries worked once I’d exported the LD_LIBRARY_PATH as shown in my post above. So should all work fine for you now.

Copying the binaries from CentOS 7 most likely will not work since the library versions will be different, even if it was Rocky 8 rather than Rocky 9.

I created a new VM, followed your instructions exactly (only needed to add epel-release first) and it compiled as you described.

I went back to my “production” server and first cleaned up what I had done previously, then followed the exact same steps again. No complaints from configure but it won’t make.

Welcome to Mapnik...

Notice: dependencies not met for plugin 'postgis', not building...
Notice: dependencies not met for plugin 'pgraster', not building...
Notice: dependencies not met for plugin 'gdal', not building...
Notice: dependencies not met for plugin 'ogr', not building...
scons: done reading SConscript files.

It then runs until it gets to here:

In file included from test/unit/datasource/../../../plugins/input/postgis/connection_manager.hpp:26,
                 from test/unit/datasource/postgis.cpp:31:
test/unit/datasource/../../../plugins/input/postgis/connection.hpp:37:10: fatal error: libpq-fe.h: No such file or directory
   37 | #include "libpq-fe.h"
      |          ^~~~~~~~~~~~
compilation terminated.
scons: *** [test/unit/datasource/postgis.o] Error 1
scons: building terminated because of errors.
make: *** [Makefile:48: mapnik] Error 2

When I get a bit more motivated and a lot less sleep deprived I’ll look into this further. If I can’t get it to compile on this machine I’ll just copy the files over from the VM.

Thanks for your help Ian. I’m going to leave this for a few days, as I have other things I need to attend to. If I get it solved I’ll report back here.

That would suggest:

dnf install libpq-devel

based on the fact it’s looking for libpq-fe.h. More precise is:

root@rocky9:~# dnf provides */libpq-fe.h
Updating Subscription Management repositories.
Last metadata expiration check: 0:05:24 ago on Tue 27 Aug 2024 10:09:00 AM CEST.
libpq-devel-13.11-1.el9.i686 : Development files for building PostgreSQL client
                             : tools
Repo        : Rocky_Linux_9_AppStream
Matched from:
Filename    : /usr/include/libpq-fe.h

which would suggest not all the dependencies have been installed on your production server. In which case you can just follow the dependencies section in my instructions to resolve that.

dnf provides */libpq-fe.h

tells that at least the package libpq-devel has such file.

You can rerun the

dnf install @development python3-scons boost-devel libicu-devel zlib-devel freetype-devel libxml2-devel harfbuzz-devel libpng-devel libjpeg-turbo-devel libtiff-devel libwebp-devel proj-devel cairo-devel pkgconf-pkg-config libpq-devel gdal-devel sqlite-devel

to recheck that you really have these packages.

1 Like

Thanks gents but…
I’ll just post this now but then I’m turning in for the night:

root@server ~ # dnf install @development python3-scons boost-devel libicu-devel zlib-devel freetype-devel libxml2-devel harfbuzz-devel libpng-devel libjpeg-turbo-devel libtiff-devel libwebp-devel proj-devel cairo-devel pkgconf-pkg-config libpq-devel gdal-devel sqlite-devel
Last metadata expiration check: 0:01:03 ago on Tue 27 Aug 2024 07:37:47 PM AEST.
Package python3-scons-4.5.2-1.el9.noarch is already installed.
Package boost-devel-1.75.0-8.el9.x86_64 is already installed.
Package libicu-devel-67.1-9.el9.x86_64 is already installed.
Package zlib-devel-1.2.11-40.el9.x86_64 is already installed.
Package freetype-devel-2.10.4-9.el9.x86_64 is already installed.
Package libxml2-devel-2.9.13-6.el9_4.x86_64 is already installed.
Package harfbuzz-devel-2.7.4-10.el9.x86_64 is already installed.
Package libpng-devel-2:1.6.37-12.el9.x86_64 is already installed.
Package libjpeg-turbo-devel-2.0.90-7.el9.x86_64 is already installed.
Package libtiff-devel-4.4.0-12.el9.x86_64 is already installed.
Package libwebp-devel-1.2.0-8.el9.x86_64 is already installed.
Package proj-devel-8.2.0-1.el9.x86_64 is already installed.
Package cairo-devel-1.17.4-7.el9.x86_64 is already installed.
Package pkgconf-pkg-config-1.7.3-10.el9.x86_64 is already installed.
Package postgresql13-devel-13.16-2PGDG.rhel9.x86_64 is already installed.
Package gdal-devel-3.4.3-2.el9.x86_64 is already installed.
Package sqlite-devel-3.34.1-7.el9_3.x86_64 is already installed.
Dependencies resolved.
====================================================================================================================================
 Package                        Architecture                  Version                          Repository                      Size
====================================================================================================================================
Installing Groups:
 Development Tools                                                                                                                 

Transaction Summary
====================================================================================================================================

Is this ok [y/N]: y
Complete!

BTW, lets take it as read that I know not to do stuff as root under normal circumstances.

So where was it looking?

It’s possible that the clean VM guest has a different build environment to the production machine, e.g. if the include and lib dirs were set different.

And this is where we differ, my instructions said installing libpq-devel, it doesn’t have this package. So I was right in my previous post, that your configure didn’t find libpq-fe.h because the dependency wasn’t met.

Therefore, you should only need now what I posted in my last post:

I suggest following my documentation on the prod server as per my instructions post fully and remove stuff that is conflicting and stopping you from installing the correct packages. Whatever you have done here is messed up on the prod server, which is proved since you built a clean server and it worked.