c++compiler-errorscompilationsconsmapnik

Error while building Mapnik (a c++ program)


I am trying to build Mapnik from source on my local Linux Mint 21.2 machine (source code on GitHub.

When compiling, it stops due to an error.

include/mapnik/filesystem.hpp:38:21: error: expected namespace name
namespace fs = std::filesystem;
               ~~~~~^
include/mapnik/filesystem.hpp:39:25: error: no type named 'error_code' in namespace 'std'
using error_code = std::error_code;
                   ~~~~~^
src/fs.cpp:40:12: error: use of undeclared identifier 'fs'
    return fs::exists(filepath);
           ^

There are many more later errors following from these, but this is where it starts.

Edit: There are also numerous warnings before about unary functions being deprecated.

In file included from mason_packages/.link/include/boost/type_index/stl_type_index.hpp:47:
mason_packages/.link/include/boost/container_hash/hash.hpp:131:33: warning: 'unary_function<std::type_index, unsigned long>' is deprecated [-Wdeprecated-declarations]
        struct hash_base : std::unary_function<T, std::size_t> {};
                                ^

Here is what I did:

I tried following instructions from the Mapnik Install Guide for Linux

They are specifically warning about needing a compiler that is up to date with the C++14 Standard. So I suspect it has something to do with me having the wrong compiler.

I successfully added the ubuntu-toolchain-r/test PPA in order to install recent compiler versions. But: When I try to install gcc-6, it says that there is no such package, but it is referenced by another package. I am confused. I figure gcc-6 is too old to be in the PPA anymore, as the current version is gcc-12, but maybe it was current at the time the Install Wiki was written.

So I figured that my current versions of gcc, clang and g++ might be recent enough because that install page was last updated in 2020.

These are my versions:

So my question is: Are the above errors introduced by using an inappropriate compiler which does not understand these lines?

Therefore, I think it is a c++ question, because some of you might know this kind of error.


Solution

  • I successfully managed to avoid the errors completely by compiling with C++17 standard instead of the default C++14 standard.

    How to set this flag during configuration:

    ./configure CXX_STD="17"
    

    See the whole struggle in Issue 4405 on Mapnik Repo. To get to a functional complete build, additional patches are needed unfortunately.