在Windows下编译Mapnik的依赖库

在Windows下编译Mapnik是非常复杂乏味的。这篇文章的目标是为构建独立的软件包提供简洁的说明,无论是使用VC++2008,2010或者2012。我们希望在不久的将来,mapnik可以完全自动化构建。
1.先决条件:
visual c++ 2008,2010或者2012 Express 或者 Professional版。
  • http://www.microsoft.com/visualstudio/en-us/products/2008-editions/visual-basic-express
  • http://www.microsoft.com/visualstudio/en-us/products/2010-editions/visual-basic-express
GNU Unix 工具(GnuWin32)
  • bsdtar
PS:下载的安装包名称为 libarchive-2.4.12-1-setup.exe
  • make
PS:下载的安装包名称为 "make-3.81.exe"  
  • wget
PS:下载的安装包名称为 "wget-1.11.4-1-setup.exe"
msysgit   - install into “c:/Git” to avoid issues with spaces in paths
PS:下载的安装包名称为 "Git-1.7.7.1-preview20111027.exe"
unzip (from   msysgit )
patch (from   msysgit )
sed (from   msysgit )
curl (from   msysgit )
cygwin   (install bash,make,coreutils) - needed to build pixman and icu (vs 2008)
PS:下载的安装包名称为 "setup-x86.exe"
PS:将上述几个安装包下载安装即可。

2.环境
我们将使用Visual Studio 2008(或者2010、2012)的命令提示符和GNU工具。请确保路径设置正确和GNU工具可在VC++命令提示符中使用。 %PATH%变量的顺序是很重要的(GIT/Cygwin/GnuWin32)。
在cmd下输入的命令行:
set PATH=%PATH%;c:\git\bin;c:\cygwin\bin;c:\GnuWin32\bin
set ROOTDIR=c:\dev2
cd %ROOTDIR%
mkdir packages 
set PKGDIR=%ROOTDIR%/packages
设置需要下载包的版本:
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 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
下载:
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 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

If BOOST and EXPAT don't seem to download properly by CURL, check the file you get. It probably contains
an error/redirect, telling you to visit their project download URLs like these to select a mirror:
http://sourceforge.net/projects/boost/files/boost/1.49.0/boost_1_49_0.tar.gz/download
http://downloads.sourceforge.net/project/expat/expat_win32/2.1.0/expat-win32bin-2.1.0.exe

cd %ROOTDIR%
PS:上边都是直接通过命令行进行下载的,也可以直接进入下载地址自己手动进行下载。

构建独立的引用包:
注意:不同的vc++版本可能需要不同的软件包,为了避免在运行时发生冲突,每个不同的版本最好是放在单独的文件夹下。

ICU
解压ICU包的命令行:
bsdtar xvfz %PKGDIR%\icu4c-4_8_1_1-src.tgz
在VS2008下编译的命令行:
cd icu/source
bash ./runConfigure Cygwin/MSVC --prefix=%ROOTDIR%\icu
make install
PS:在VS2008下编译ICU时出现了错误,没有解决!

在VS2010和VS2012下编译的命令行:
cd icu/
msbuild source\allinone\allinone.sln /t:Rebuild  /p:Configuration="Release" /p:Platform=Win32

cd %ROOTDIR%
PS:如果提示找不到msbuild命令,需要设置环境变量。首先找到msbuild,然后将msbuild所在的路径添加到环境变量中。

BOOST
BOOST编译的命令行
bsdtar xzf %PKGDIR%/boost_1_%BOOST_VERSION%_0.tar.gz
cd boost_1_%BOOST_VERSION%_0
#set to -vc110 if using MSVC 2012
set BOOST_PREFIX=boost-%BOOST_VERSION%-vc100
bootstrap.bat
# note for VS2012, use toolset=msvc-11.0 and VS2010 use toolset=msvc-10.0 
bjam toolset=msvc --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

# if you need python
# note for VS2012, use toolset=msvc-11.0 and VS2010 use toolset=msvc-10.0 
bjam toolset=msvc --prefix=..\\%BOOST_PREFIX% --with-python python=2.7 release link=static --build-type=complete install

cd %ROOTDIR%

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\Microsoft SDKs\Windows\v7.1\Include

cd %ROOTDIR%
PS:在编译过程中出现问题可参考 http://blog.csdn.net/wuliqunaowuliqunao/article/details/7911659







你可能感兴趣的:(在Windows下编译Mapnik的依赖库)