Mapnik Windows10 compilation

Mapnik Windows10 Compilation

Table of Contents

Mapnik Windows10 compilation

1. Compilation tool preparation:

2. Environment variable settings:

3. Download the decompression package:

4. Source code compilation dependencies:

5. Compile mapnik source code

6. mapnik windows official website compiled version


1. Compilation tool preparation:

  1. vs2010 (download by yourself)
  2. GnuWin32 (required) https://jaist.dl.sourceforge.net/project/gnuwin32/make/3.81/make-3.81-bin.zip
  3. git (https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/msysgit/Git-1.7.7.1-preview20111027.exe)
  4. patch (2)
  5. curl(2)
  6. cygwin http://www.cygwin.org/setup-x86.exe
  7. unzip (2)

Tool link: (posted)

2. Environment variable settings:

set PATH=%PATH%;c:\git\bin;c:\cygwin\bin;c:\GnuWin32\bin
set ROOTDIR=c:\dev2
cd %ROOTDIR%
mkdir packages
set PKGDIR=%ROOTDIR%/packages

Note: Please set the path according to your needs: the above can be set in the cmd command line

Version settings:

set ICU_VERSION=4.8
setBOOST_VERSION=49
set ZLIB_VERSION=1.2.8
set LIBPNG_VERSION=1.5.17
set JPEG_VERSION=8d
set WEBP_VERSION=0.4.0
set FREETYPE_VERSION=2.4.9
set POSTGRESQL_VERSION=9.1.3
set TIFF_VERSION=4.0.0beta7
set PROJ_VERSION=4.8.0
set PROJ_GRIDS_VERSION=1.5
set GDAL_VERSION=1.9.0
set LIBXML2_VERSION=2.7.8
setPIXMAN_VERSION=0.28.2
set CAIRO_VERSION=1.12.14
set SQLITE_VERSION=3071100
set EXPAT_VERSION=2.1.0
set GEOS_VERSION=3.3.3

3. Download the decompression package:

wget https://raw.github.com/mapnik/mapnik-packaging/master/windows/cairo-win32.patch --no-check-certificate
wget https://raw.github.com/mapnik/mapnik-packaging/master/windows/libxml.patch --no-check-certificate

cd %PKGDIR%
curl http://iweb.dl.sourceforge.net/project/boost/boost/1.%BOOST_VERSION%.0/boost_1_%BOOST_VERSION%_0.tar.gz -O
curl http://www.ijg.org/files/jpegsr%JPEG_VERSION%.zip -O
curl https://webp.googlecode.com/files/libwebp-%WEBP_VERSION%-windows-x86.zip -O
curl http://ftp.igh.cnrs.fr/pub/nongnu/freetype/freetype-%FREETYPE_VERSION%.tar.gz -O
curl http://ftp.postgresql.org/pub/source/v%POSTGRESQL_VERSION%/postgresql-%POSTGRESQL_VERSION%.tar.gz -O
curl ftp://ftp.simplesystems.org/pub/libpng/png/src/libpng15/libpng-%LIBPNG_VERSION%.tar.gz -O
curl http://www.zlib.net/zlib-%ZLIB_VERSION%.tar.gz -O
curl http://download.osgeo.org/libtiff/tiff-%TIFF_VERSION%.tar.gz -O
curl http://www.cairographics.org/releases/pixman-%PIXMAN_VERSION%.tar.gz -O
curl http://www.cairographics.org/releases/cairo-?IRO_VERSION%.tar.xz -O
curl http://download.icu-project.org/files/icu4c/4.8.1.1/icu4c-4_8_1_1-src.tgz -O
curl ftp://xmlsoft.org/libxml2/libxml2-%LIBXML2_VERSION%.tar.gz -O
curl http://iweb.dl.sourceforge.net/project/expat/expat_win32/%EXPAT_VERSION%/expat-win32bin-%EXPAT_VERSION%.exe -O
curl http://download.osgeo.org/gdal/gdal-%GDAL_VERSION%.tar.gz -O
curl http://www.sqlite.org/sqlite-amalgamation-%SQLITE_VERSION%.zip -O
curl http://download.osgeo.org/proj/proj-%PROJ_VERSION%.tar.gz -O
curl http://download.osgeo.org/proj/proj-datumgrid-%PROJ_GRIDS_VERSION%.zip -O
curl http://download.osgeo.org/geos/geos-%GEOS_VERSION%.tar.bz2 -O


cd %ROOTDIR%

Alternative path:
BOOST: http://sourceforge.net/projects/boost/files/boost/1.49.0/boost_1_49_0.tar.gz/download
EXPAT: http://downloads.sourceforge.net/project/expat/expat_win32/2.1.0/expat-win32bin-2.1.0.exe

All of the above can be downloaded manually (a total of 18 dependencies, 2 of which patch files can be obtained from https://github.com/mapnik/mapnik-packaging.git)

4. Source code compilation dependencies:

# Use the vs2010 command line tool to compile the source code

#1 ICU compilation
bsdtar xvfz %PKGDIR%\icu4c-4_8_1_1-src.tgz
cd icu/
msbuild source\allinone\allinone.sln /t:Rebuild /p:Configuration="Release" /p:Platform=Win32

cd %ROOTDIR%

# 2 boost compilation
bsdtar xzf %PKGDIR%/boost_1_%BOOST_VERSION%_0.tar.gz
cd boost_1_%BOOST_VERSION%_0
#Set MSVC version
set BOOST_PREFIX=boost-%BOOST_VERSION%-vc100
bootstrap.bat
# Set up msvc 10.0 compilation
bjam toolset=msvc-10.0 --prefix=..\%BOOST_PREFIX% --with-thread --with-filesystem --with-date_time --with-system --with-program_options --with-regex --with -chrono --disable-filesystem2 -sHAVE_ICU=1 -sICU_PATH=%ROOTDIR%\icu -sICU_LINK=%ROOTDIR%\icu\lib\icuuc.lib release link=static install --build-type=complete

# python lib compile
bjam toolset=msvc-10.0 --prefix=..\%BOOST_PREFIX% --with-python python=2.7 release link=static --build-type=complete install

# python dynamic link library compilation dll
bjam toolset=msvc-10.0 --prefix=..\%BOOST_PREFIX% --with-python python=2.7 release runtime-link=shared --build-type=complete install

cd %ROOTDIR%


# 3 webp compilation

unzip %PKGDIR%\libwebp-%WEBP_VERSION%-windows-x86.zip
rename libwebp-%WEBP_VERSION%-windows-x86 webp

cd %ROOTDIR%


#4 Jpeg compilation

unzip %PKGDIR%\jpegsr%JPEG_VERSION%.zip
rename jpeg-%JPEG_VERSION% jpeg
cdjpeg
copy jconfig.txt jconfig.h
nmake /f Makefile.vc nodebug=1


#If you receive an error about not finding Win32.mak, you may need to do something #like:
#set INCLUDE=%include%;C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Include (depending on the specific situation)

cd %ROOTDIR%

#5 Freetype compilation

bsdtar xfz "%PKGDIR%\freetype-%FREETYPE_VERSION%.tar.gz"
rename freetype-%FREETYPE_VERSION% freetype
cd freetype

msbuild builds\win32\vc2010\freetype.sln /p:Configuration=Release /p:Platform=Win32

move objs\win32\vc2010\freetype249.lib freetype.lib
cd %ROOTDIR%


# 6 zlib compilation

bsdtar xvfz %PKGDIR%\zlib-%ZLIB_VERSION%.tar.gz
rename zlib-%ZLIB_VERSION% zlib-1.2.5

cd %ROOTDIR%

# 7 libpng compilation
bsdtar xvfz %PKGDIR%\libpng-%LIBPNG_VERSION%.tar.gz
rename libpng-%LIBPNG_VERSION% libpng

cd %ROOTDIR%\libpng\projects\vstudio\
msbuild vstudio.sln /t:Rebuild /p:Configuration="Release" /p:Platform=Win32

cd %ROOTDIR%\libpng
move projects\vstudio\Release\libpng15.lib libpng.lib
move projects\vstudio\Release\zlib.lib ..\zlib-1.2.5\zlib.lib
cd %ROOTDIR%


# 8 libpq (PostgreSQL C-interface) compilation

bsdtar xvfz "%PKGDIR%\postgresql-%POSTGRESQL_VERSION%.tar.gz"
rename postgresql-%POSTGRESQL_VERSION% postgresql
cd postgresql\src
nmake /f win32.mak

#The following error occurs, the problem is not big, just generate libpq.lib
#NMAKE : fatal error U1077: '"C:\Program Files (x86)\Windows Kits\8.0\bin\x86#\mt.EXE"' : return code '0x1f'

cd %ROOTDIR%


# 9 Tiff compilation
bsdtar xvfz %PKGDIR%\tiff-%TIFF_VERSION%.tar.gz
rename tiff-%TIFF_VERSION% tiff
cd tiff
set P1=s/\^#JPEG_SUPPORT.*/JPEG_SUPPORT = 1/;
set P2=s/\^#JPEGDIR.*/JPEGDIR = %ROOTDIR:\=\\%\\jpeg/;
set P3=s/\^#JPEG_INCLUDE/JPEG_INCLUDE/;
set P4=s/\^#JPEG_LIB.*/JPEG_LIB = \$(JPEGDIR^)\\libjpeg.lib/;
set P5=s/\^#ZIP_SUPPORT.*/ZIP_SUPPORT = 1/;
set P6=s/\^#ZLIBDIR.*/ZLIBDIR = %ROOTDIR:\=\\%\\zlib-1.2.5/;
set P7=s/\^#ZLIB_INCLUDE/ZLIB_INCLUDE/;

set P8=s/\^#ZLIB_LIB.*/ZLIB_LIB = \$(ZLIBDIR^)\\zlib.lib/;

set PATTERN="%P1%%P2%%P3%%P4%%P5%%P6%%P7%%P8%"
sed %PATTERN% nmake.opt > nmake.opt.fixed
move /Y nmake.opt.fixed nmake.opt
nmake /f Makefile.vc
cd %ROOTDIR%


#10 Pixman compilation
bsdtar xvfz %PKGDIR%\pixman-%PIXMAN_VERSION%.tar.gz
rename pixman-%PIXMAN_VERSION% pixman
cd pixman\pixman
make -f Makefile.win32 "CFG=release"
cd %ROOTDIR%


#11 Cairo Compilation
bsdtar %PKGDIR%\cairo-?IRO_VERSION%.tar.xz
rename cairo-?IRO_VERSION% cairo
cd cairo

#@ Modify the file build\Makefile.win32.features
#@CAIRO_HAS_FT_FONT=1 (can be found by searching for keywords)

#@ Modify the file build\Makefile.win32.common
#@ Modify zdll.lib to zlib.lib Modify the path of zlib to zlib-1.2.5
#@ Modification example:
#@ ifeq ($(CAIRO_HAS_PS_SURFACE)$(CAIRO_HAS_PDF_SURFACE),00)
#@ else
#@ ZLIB_CFLAGS + = -I$(top_srcdir)/../zlib-1.2.5/
#@CAIRO_LIBS + = $(top_builddir)/../zlib-1.2.5/zlib.lib
#@ endif
#@ Add freetype lib path freetype.lib to CAIRO_LIBS variable
#@ Modification example:
#@ Add the following under the line CAIRO_LIBS = gdi32.lib msimg32.lib user32.lib:

#@ LIBPNG_CFLAGS + = -I$(top_srcdir)/../freetype/
#@CAIRO_LIBS + = $(top_builddir)/../freetype/freetype.lib


set INCLUDE=%INCLUDE%;%ROOTDIR%\zlib-1.2.5
set INCLUDE=%INCLUDE%;%ROOTDIR%\libpng
set INCLUDE=%INCLUDE%;%ROOTDIR%\pixman\pixman
set INCLUDE=%INCLUDE%;%ROOTDIR%\cairo\boilerplate
set INCLUDE=%INCLUDE%;%ROOTDIR%\cairo
set INCLUDE=%INCLUDE%;%ROOTDIR%\cairo\src
set INCLUDE=%INCLUDE%;%ROOTDIR%\freetype\include
make -f Makefile.win32 "CFG=release"

del src\cairo-version.h
cd %ROOTDIR%


# 12 LibXML2 compilation

bsdtar xvfz %PKGDIR%\libxml2-%LIBXML2_VERSION%.tar.gz
rename libxml2-%LIBXML2_VERSION% libxml2

cd libxml2\win32
cscript configure.js compiler=msvc prefix=%ROOTDIR%\libxml2 iconv=no icu=yes include=%ROOTDIR%\icu\include lib=%ROOTDIR%\icu\lib
patch -p1 < %ROOTDIR%\libxml.patch
nmake /f Makefile.msvc

cd %ROOTDIR%


# 13 Proj4 compilation
bsdtar xfz %PKGDIR%\proj-%PROJ_VERSION%.tar.gz
rename proj-%PROJ_VERSION% proj
cd proj/nad

unzip -o ../../packages/proj-datumgrid-%PROJ_GRIDS_VERSION%.zip

cd..
nmake /f Makefile.vc
cd %ROOTDIR%


# 14 Install Expat
start packages\expat-win32bin-%EXPAT_VERSION%.exe


# 15 GDAL
bsdtar xvfz %PKGDIR%\gdal-%GDAL_VERSION%.tar.gz
mkdir gdal

rename gdal-%GDAL_VERSION% gdal/gdal
cd gdal/gdal

#@ Manually modify the nmake.opt file: (note)
#@ EXPAT_DIR="C:\Program Files (x86)\Expat 2.1.0"
#@ EXPAT_INCLUDE = -I$(EXPAT_DIR)/source/lib
#@ EXPAT_LIB = $(EXPAT_DIR)/bin/libexpat.lib
#@ Modify the nmake.opt file and uncomment it

# compile
nmake /f makefile.vc MSVC_VER=1600


cd %ROOTDIR%


# 16 sqlite compilation

unzip %PKGDIR%\sqlite-amalgamation-%SQLITE_VERSION%.zip
rename sqlite-amalgamation-%SQLITE_VERSION% sqlite

# 17 protobuf compilation
#Download and decompress protobuf: https://protobuf.googlecode.com/files/protobuf-2.5.0.zip

rename protobuf-2.5.0 protobuf
cd protobuf\vcprojects
vcupgrade libprotobuf-lite.vcproj
vcupgrade libprotobuf.vcproj
vcupgrade protoc.vcproj
msbuild libprotobuf-lite.vcxproj /p:Configuration="Release" /p:Platform=Win32
msbuild libprotobuf.vcxproj /p:Configuration="Release" /p:Platform=Win32

extract_includes.bat

cd %ROOTDIR%

# 18 GEOS

bsdtar xvf %PKGDIR%\geos-%GEOS_VERSION%.tar.bz2
rename geos-%GEOS_VERSION% geos

cd geos
mkdir build
cd build
cmake -G "NMake Makefiles" ..
nmake /f Makefile geos

Compile the above 18 source codes. I have modified the above compilation according to the actual situation. There are many problems encountered, which must be solved one by one. Compiling the source code requires patience and more time. It is slow when encountering problems. Resolve slowly. (from scratch)

5. Compile mapnik source code

1. Download mapnik source code:

git clone https://github.com/mapnik/mapnik.git -b 2.3.x mapnik

Location: placed in the %ROOTDIR% folder

2. Download mapnik-windows compiled source code:

git clone https://github.com/mapnik/mapnik-packaging.git

Modify the mapnik compilation bat (mapnik-packaging/windows/build_mapnik.bat) to ensure that the location is the same as the one you compiled.

Run bat and compilation starts

6. mapnik windows official website compiled version

Download address: http://mapnik.s3.amazonaws.com/dist/v2.2.0/mapnik-win-sdk-v2.2.0.zip

Note: The official website version is (release win32 c++)

python version: portal

Write at the end:

1. This compiled version is the release win32 version

2. The article comes from practice, and I compiled it successfully! Compilation requires a lot of patience, and with 18 dependent libraries, there are still many problems. It is not recommended that you compile it yourself:

3. Source code compilation under Linux also requires the same dependent libraries, but you can directly sudo apt install mapnik (the source configuration is omitted)

Compilation success sign: mapnik.dll and mapnik.lib are generated