Mapnik Windows10编译

Mapnik Windows10编译

目录

Mapnik Windows10编译

1、编译工具准备:

2、环境变量设置:

3、下载解压包:

4、源码编译依赖:

5、编译mapnik源码

6、mapnik windows官网编译版本


1、编译工具准备:

  1. vs2010 (自行下载)
  2. GnuWin32(必要)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)

工具链接:(已贴)

2、环境变量设置:

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

注:请根据你的需求设置路径:以上可在cmd命令行中设置

版本设置:

set ICU_VERSION=4.8
set BOOST_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
set PIXMAN_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、下载解压包:

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

备选路径:
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

以上都可以手动下载(共18个依赖,其中2个patch文件可以从 https://github.com/mapnik/mapnik-packaging.git  获取)

 

4、源码编译依赖:

# 使用vs2010命令行工具编译一下源码

# 1 ICU编译
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编译
bsdtar xzf %PKGDIR%/boost_1_%BOOST_VERSION%_0.tar.gz
cd boost_1_%BOOST_VERSION%_0
#设置 MSVC 版本
set BOOST_PREFIX=boost-%BOOST_VERSION%-vc100
bootstrap.bat
# 设置msvc 10.0编译
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编译
bjam toolset=msvc-10.0 --prefix=..\\%BOOST_PREFIX% --with-python python=2.7 release link=static --build-type=complete install

# python 动态链接库编译 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编译

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

cd %ROOTDIR%


# 4 Jpeg编译

unzip %PKGDIR%\jpegsr%JPEG_VERSION%.zip
rename jpeg-%JPEG_VERSION% jpeg
cd jpeg 
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(根据具体情况定)

cd %ROOTDIR%

# 5 Freetype编译

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

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

cd  %ROOTDIR%

# 7 libpng编译
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)编译

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

#发生如下错误,问题不大 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 编译
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编译
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编译
bsdtar %PKGDIR%\cairo-%CAIRO_VERSION%.tar.xz
rename cairo-%CAIRO_VERSION% cairo
cd cairo

#@ 修改文件 build\Makefile.win32.features  
#@ CAIRO_HAS_FT_FONT=1   (搜索关键词可找到)

#@ 修改文件build\Makefile.win32.common
#@ 修改 zdll.lib 为 zlib.lib 修改 zlib的路径为 zlib-1.2.5
#@ 修改示例:
#@ 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
#@ 添加 freetype lib 路径 freetype.lib 到 CAIRO_LIBS 变量
#@ 修改示例:
#@ 在 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编译

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编译
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 安装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

#@ 手动修改nmake.opt文件:(注意)
#@ EXPAT_DIR="C:\Program Files (x86)\Expat 2.1.0"
#@ EXPAT_INCLUDE = -I$(EXPAT_DIR)/source/lib
#@ EXPAT_LIB = $(EXPAT_DIR)/bin/libexpat.lib
#@ 修改nmake.opt文件 放开注释

# 编译
nmake /f makefile.vc MSVC_VER=1600


cd %ROOTDIR%


# 16 sqlite编译

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

# 17 protobuf编译
#下载解压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

编译以上18个源码,以上编译我已根据实践情况进行修改啦,其中遇到是问题非常的多,必须一个一个的解决,编译源码需要的是耐心,需要的时间也比较多,遇到问题慢慢解决。(从无到有)

Mapnik Windows10编译_第1张图片

5、编译mapnik源码

1、下载mapnik源码:

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

位置:放在  %ROOTDIR%文件夹里

2、下载mapnik——windows编译源码:

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

修改mapnik编译bat(mapnik-packaging/windows/build_mapnik.bat)保证位置与你编译的相同

运行bat,编译开始

Mapnik Windows10编译_第2张图片

6、mapnik windows官网编译版本

下载地址:http://mapnik.s3.amazonaws.com/dist/v2.2.0/mapnik-win-sdk-v2.2.0.zip

注:官网版本为( release win32 c++)

python版本:传送门

写在最后:

1、此编译版本为release   win32版本  

2、文章来源于实践,我编译成功啦!编译需要很多的耐心,18个依赖库,问题还是有很多的。不建议各位自己编译:

3、Linux下源码编译也需要同样的依赖库,但是可以直接sudo apt install mapnik (需配置源 略)

 

 

编译成功标志:mapnik.dll和mapnik.lib生成

Mapnik Windows10编译_第3张图片

 

 

你可能感兴趣的:(Mapnik,C++)