mapnik / mapnik

Mapnik is an open source toolkit for developing mapping applications

Home Page:http://mapnik.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Building on Mac M1 can not find several linked libraries

adamakhtar opened this issue · comments

I am under the impression to build mapnik and mapnik-python I must build both projects from their v3.0.x branches. This means It is not possible to build mapnik-python against a brew installed mapnik as that version is 3.1 ( I have tried but the build python bindings do not work).

So I'm trying to build mapnik from source but I when I run ./configure on the 3.0.x branch for mapnik several libraries are not discoverable despite me explicitly linking to what I believe to be valid paths.

Namely GDAL, ICU and PROJ are not discoverable by ./configure.

This is strange as I can cd into the supplied paths and see they are valid.

Here is the full command I am running

./configure \
PROJ_INCLUDES=/opt/homebrew/opt/proj/include \    
PROJ_LIBS=/opt/homebrew/opt/proj/lib \
GDAL_CONFIG=/opt/homebrew/opt/gdal/bin/gdal-config \
ICU_INCLUDES=/opt/homebrew/opt/icu4c/include \
ICU_LIBS=/opt/homebrew/opt/icu4c/lib \
PYTHON=/opt/homebrew/opt/python@3.9 \
BOOST_INCLUDES=/opt/homebrew/opt/boost/include \
BOOST_LIBS=/opt/homebrew/opt/boost/lib \
CAIRO=True \
CPP_TESTS=False \
FREETYPE_CONFIG=/opt/homebrew/opt/freetype/bin/freetype-config \
HB_INCLUDES=/opt/homebrew/opt/harfbuzz/include \
HB_LIBS=/opt/homebrew/opt/harfbuzz/lib \
ICU_INCLUDES=/opt/homebrew/opt/icu4c/include \
ICU_LIBS=/opt/homebrew/opt/icu4c/lib \
INPUT_PLUGINS=all \
JPEG_INCLUDES=/opt/homebrew/opt/jpeg/include \
JPEG_LIBS=/opt/homebrew/opt/jpeg/lib \
NIK2IMG=False \
PG_CONFIG=/opt/homebrew/opt/postgresql/bin/pg_config \
PNG_INCLUDES=/opt/homebrew/opt/libpng/include \
PNG_LIBS=/opt/homebrew/opt/libpng/lib \
TIFF_INCLUDES=/opt/homebrew/opt/libtiff/include \
TIFF_LIBS=/opt/homebrew/opt/libtiff/lib \
WEBP_INCLUDES=/opt/homebrew/opt/webp/include \
WEBP_LIBS=/opt/homebrew/opt/webp/lib \

I get

Checking for C library proj... no
Could not find optional header or shared library for proj
...
Checking for PROJ_LIB directory...Failed to detect (mapnik-config will have null value)
Checking for ICU data directory...Failed to detect (mapnik-config will have null value)
Checking for GDAL data directory...Failed to detect (mapnik-config will have null value)
... 
Full output of ./configure
Welcome to Mapnik...

Configuring build environment...
SCons CONFIG found: 'config.py', variables will be inherited...
Configuring on Darwin in *release mode*...
Checking for pkg-config... yes
Checking for freetype2... yes
Checking for dlfcn.h support ... yes
Checking if compiler (c++) supports -std=c++11 flag... (cached) yes
Checking for C library z... yes
Checking for C++ library icuuc... yes
Checking for ICU version >= 4.2... found: icu 70.1
(cached) Checking for C++ library harfbuzz... yes
Checking for HarfBuzz version >= 0.9.34... found: HarfBuzz 4.2.1
Checking for HarfBuzz with freetype support
(cached) yes
Searching for boost libs and headers... (cached)
Found boost libs: /opt/homebrew/opt/boost/lib
Found boost headers: /opt/homebrew/opt/boost/include
Checking for C++ header file boost/version.hpp... yes
Checking for Boost version >= 1.47... yes
Found boost lib version... 1_78
Checking for C++ library boost_system... yes
Checking for C++ library boost_filesystem... yes
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 ... yes
Checking if boost_regex was built with ICU unicode support... (cached) yes
Checking for C library jpeg... yes
Checking for C library proj... no
Could not find optional header or shared library for proj
Checking for C library png... yes
Checking for C library webp... yes
Checking for C library tiff... yes
Checking for PROJ_LIB directory...Failed to detect (mapnik-config will have null value)
Checking for ICU data directory...Failed to detect (mapnik-config will have null value)
Checking for GDAL data directory...Failed to detect (mapnik-config will have null value)
Checking for requested plugins dependencies...
Checking for gdal-config --libs... yes
Checking for gdal-config --cflags... yes
Checking for name of gdal library... yes
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... yes
Checking for C++ library gdal... yes
Checking for pg_config... yes
Checking for pg_config... yes
Checking for C library sqlite3... yes
Checking if SQLite supports RTREE... (cached) yes
Checking for cairo... yes
Checking for cairo lib and include paths... yes
Checking for cairo freetype font support ... yes

All Required dependencies found!

Overwriting and re-saving file 'config.py'...
Will hold custom path variables from commandline and python config file(s)...

Note: will build without these OPTIONAL dependencies:
   - proj (Proj.4 C Projections library | configure with PROJ_LIBS & PROJ_INCLUDES | more info: http://trac.osgeo.org/proj/)

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

I am running this on an M1 Mac. All mapnik dependencies are installed via brew. I used brew --prefix name_of_package to find the paths to each of the packages. This is how the brew formula for mapnik 3.1 does it.

Can anyone see what I am doing wrong.

commented

Incase anyone else is facing this issue. This is because in SConstruct it is checking whether PROJ is installed.
However since version 8.0+ this dependency has been removed and thus it fails.

// This is narly, could eventually be replaced using https://github.com/OSGeo/proj.4/pull/551] #include <proj_api.h>

If you want to by pass the check, on line 1467, comment this section:

if env['PROJ']: OPTIONAL_LIBSHEADERS.append(['proj', 'proj_api.h', False,'C','-DMAPNIK_USE_PROJ4']) inc_path = env['%s_INCLUDES' % 'PROJ'] lib_path = env['%s_LIBS' % 'PROJ'] env.AppendUnique(CPPPATH = fix_path(inc_path)) env.AppendUnique(LIBPATH = fix_path(lib_path)) else: env['SKIPPED_DEPS'].append('proj')

commented

After playing around with configuration and building on Apple M1, its possible to get configuration to work with all the dependencies.

The SConstruct check for PROJ can be resolved by installing

brew install proj@7

and then applying the custom define in the build command

CUSTOM_DEFINES="-DACCEPT_USE_OF_DEPRECATED_PROJ_API_H=1"

as described here

the full build command

./configure PREFIX=/opt/mapnik \
BOOST_INCLUDES="/opt/homebrew/opt/boost@1.79/include" \
BOOST_LIBS="/opt/homebrew/opt/boost@1.79/lib" \
CAIRO_INCLUDES="/opt/homebrew/Cellar/cairo/1.16.0_5/include" \
CAIRO_LIBS="/opt/homebrew/Cellar/cairo/1.16.0_5/lib" \
CUSTOM_CFLAGS="-I/opt/homebrew/Cellar/proj@7/7.2.1/include" \
CUSTOM_CXXFLAGS="-I/opt/homebrew/include" \
CUSTOM_LDFLAGS="-L/opt/homebrew/lib" \
CUSTOM_DEFINES="-DACCEPT_USE_OF_DEPRECATED_PROJ_API_H=1" \
FREETYPE_INCLUDES="/opt/homebrew/Cellar/freetype/2.12.1/include/freetype2" \
FREETYPE_LIBS="/opt/homebrew/Cellar/freetype/2.12.1/lib" \
GDAL_CONFIG="/opt/homebrew/bin/gdal-config" \
HB_INCLUDES="/opt/homebrew/Cellar/harfbuzz/5.1.0/include" \
HB_LIBS="/opt/homebrew/Cellar/harfbuzz/5.1.0/lib" \
ICU_INCLUDES="/opt/homebrew/opt/icu4c/include" \
ICU_LIBS="/opt/homebrew/opt/icu4c/lib" \
JPEG_INCLUDES="/opt/homebrew/Cellar/jpeg-turbo/2.1.3/include" \
JPEG_LIBS="/opt/homebrew/Cellar/jpeg-turbo/2.1.3/lib" \
PG_INCLUDES="/opt/homebrew/Cellar/libpq/14.4/include" \
PG_LIBS="/opt/homebrew/Cellar/libpq/14.4/lib" \
PNG_INCLUDES="/opt/homebrew/Cellar/libpng/1.6.37/include" \
PNG_LIBS="/opt/homebrew/Cellar/libpng/1.6.37/lib" \
PROJ_INCLUDES="/opt/homebrew/Cellar/proj@7/7.2.1/include" \
PROJ_LIBS="/opt/homebrew/Cellar/proj@7/7.2.1/lib" \
SQLITE_INCLUDES="/opt/homebrew/opt/sqlite/include" \
SQLITE_LIBS="/opt/homebrew/opt/sqlite/lib" \
TIFF_INCLUDES="/opt/homebrew/Cellar/libtiff/4.4.0_1/include" \
TIFF_LIBS="/opt/homebrew/Cellar/libtiff/4.4.0_1/lib" \
WEBP_INCLUDES="/opt/homebrew/Cellar/webp/1.2.4/include" \
WEBP_LIBS="/opt/homebrew/Cellar/webp/1.2.4/lib"

but after configuration and build there are still issues for PROJ dependency:

  • the current brew's gdal depends on the latest proj (9.x)
  • when using mapnik there are still complaints for PROJ usage:
Cannot initialize proj_transform for given projections without proj4 support (-DMAPNIK_USE_PROJ4): '+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0.0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs +over'->'+proj=merc +datum=WGS84 +over'

Unfortunately I'm not knowledgeable enough to know if the above message is something with my configuration or with the build of mapnik that does not correctly utilize the PROJ dependency.