Installation

Prerequisites

First, here is a quick list of the software dependencies:

  • Linux/UNIX with g++ compiler
  • libboost 1.33.0 or greater with the following libraries included:
    • thread
    • filesystem
    • regex
    • (Optional) program_options
    • (Optional) python
  • libpng
  • libjpeg
  • libtiff
  • libz
  • libfreetype2
  • proj4
  • (Optional) PostgreSQL libraries (For PostGIS support)
  • Python 1.5.2 or greater to build Mapnik
  • (Optional) Python 2.4 or greater for the Python language bindings

All of these will normally come with any modern Linux distribution. If your system does NOT have one of these installed, you will need to install the mandatory ones at the very least before proceeding further. Instructions on how to do this will come with each individual package. Also, a minimum of 256MB of RAM is recommended for the build process.

Building

Once you've installed the required software packages, the simplest way to build mapnik is to run "scons" (The software builder) without any options:

$ cd /path/to/mapnik-sourcecode
$ /path/to/python scons/scons.py

This should compile and link the mapnik library, the input plugins and the python language binding (if possible). If any mandatory dependencies are not found the build will fail, and you will need to specify custom paths to your libraries and include files (see below).

Note that the python used to run "scons" does NOT have to be the same as the one used for the python bindings.

"scons" accepts a variety of options to customize your build. This allows you to specify which components are compiled, where to find dependencies, where to install mapnik, and so on.

To see the list of available options, from the root of the source distribution, run:

$ /path/to/python scons/scons.py -h
You will get:
PREFIX: The install path "prefix"
    default: /usr/local
    actual: /usr/local

BOOST_INCLUDES: Search path for boost include files ( /path/to/BOOST_INCLUDES )
    default: /usr/include
    actual: /usr/include

BOOST_LIBS: Search path for boost library files ( /path/to/BOOST_LIBS )
    default: /usr/lib
    actual: /usr/lib

FREETYPE_CONFIG: The path to the freetype-config executable. ( /path/to/FREETYPE_CONFIG )
    default: /usr/bin/freetype-config
    actual: /usr/bin/freetype-config

PNG_INCLUDES: Search path for libpng include files ( /path/to/PNG_INCLUDES )
    default: /usr/include
    actual: /usr/include

PNG_LIBS: Search path for libpng include files ( /path/to/PNG_LIBS )
    default: /usr/lib
    actual: /usr/lib

JPEG_INCLUDES: Search path for libjpeg include files ( /path/to/JPEG_INCLUDES )
    default: /usr/include
    actual: /usr/include

JPEG_LIBS: Search path for libjpeg library files ( /path/to/JPEG_LIBS )
    default: /usr/lib
    actual: /usr/lib

TIFF_INCLUDES: Search path for libtiff include files ( /path/to/TIFF_INCLUDES )
    default: /usr/include
    actual: /usr/include

TIFF_LIBS: Search path for libtiff library files ( /path/to/TIFF_LIBS )
    default: /usr/lib
    actual: /usr/lib

PGSQL_INCLUDES: Search path for PostgreSQL include files ( /path/to/PGSQL_INCLUDES )
    default: /usr/include
    actual: /usr/include

PGSQL_LIBS: Search path for PostgreSQL library files ( /path/to/PGSQL_LIBS )
    default: /usr/lib
    actual: /usr/lib

PROJ_INCLUDES: Search path for PROJ.4 include files ( /path/to/PROJ_INCLUDES )
    default: /usr/local/include
    actual: /usr/local/include

PROJ_LIBS: Search path for PROJ.4 include files ( /path/to/PROJ_LIBS )
    default: /usr/local/lib
    actual: /usr/local/lib

PYTHON: Python executable ( /path/to/PYTHON )
    default: /usr/bin/python
    actual: /usr/bin/python

INPUT_PLUGINS: Input drivers to include
    (all|none|comma-separated list of names)
    allowed names: postgis shape raster
    default: all
    actual: postgis shape raster

BINDINGS: Language bindings to build
    (all|none|comma-separated list of names)
    allowed names: python
    default: all
    actual: python

DEBUG: Compile a debug version of mapnik
    default:
    actual:

This help should be self-explanatory! For example, if you compiled your own set of Boost libraries, you might use:

$ /path/to/python scons/scons.py BOOST_INCLUDES=/usr/local/include/boost-1_33_1 BOOST_LIBS=/usr/local/lib

Installation

Once the build has successfully completed, you can install the various files on your system by executing: $ /path/to/python scons/scons.py install By default, everything will be installed under the PREFIX '/usr/local' as such: $PREFIX/lib: libmapnik.so $PREFIX/lib/mapnik/input: input plug-ins $PREFIX/include: mapnik include files $PREFIX/bin: shapeindex utility $PYTHON_PREFIX/lib/python$PYTHON_VERSION/site-packages/mapnik: Python bindings If you're using the default PREFIX, you will most likely need to be root to perform the install.

Projections support

Here is an example on how to use it:

>>> from mapnik import Projection
registered datasource : raster
registered datasource : shape
registered datasource : postgis
>>> p = Projection(['init=epsg:42304'])
>>> p.Inverse(12345.245,143225.56)
[-94.825927695613018, 50.290732340975467]
>>>

The Projection() instance provides Inverse() and Forward() methods. For details on the possible parameters, see the PROJ.4 documentation.

Test

There currently is no easy way to test your setup, other than write some code to generate a map. One simple thing you can do is try to load the Python module, and make sure it does so without errors:

$ /path/to/python
Python 2.4.2 (#1, Jan 11 2006, 10:59:28)
[GCC 3.4.4 20050721 (Red Hat 3.4.4-2)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from mapnik import *
registered datasource : shape
registered datasource : raster
registered datasource : postgis
>>>

Comments

janr May 24, 2006 at 8:01 p.m.

I'm trying to build mapnik with Ubuntu, but I'm getting the following exception. What does it mean?

Traceback (most recent call last):
File "<string>", line 1, in ?
File "/usr/lib/python2.4/site-packages/mapnik/__init__.py", line 28, in ?
from _mapnik import *
ImportError: /usr/lib/python2.4/site-packages/mapnik/_mapnik.so: undefined symbol: _ZNK6mapnik5Layer5titleEv

luizf May 25, 2006 at 11:42 p.m.

I get a similar problem when trying to build mapnik on Slackware 10.2 with boost 1.33.1 compiled from the source.

>>> import mapnik
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "/usr/lib/python2.4/site-packages/mapnik/__init__.py", line 28, in ?
from _mapnik import *
ImportError: /usr/local/lib/libmapnik.so: undefined symbol: _Z20jpeg_finish_compressP20jpeg_compress_struct

Artem Pavlenko June 22, 2006 at 12:10 p.m.

David,
There is no support for building mapnik on win32 with scons (not yet). To build on win32 I use CMake. Drop me an email and I'll be happy to help.

Rainer September 5, 2006 at 1:46 a.m.

I am trying to compile Mapnik on RedHat EL4 and get a compiling error. I downloaded the current boost sources (1.33) and compiled them on the linux box.

I run following command to compile mapnik 0.3.0:
python scons/scons.py BOOST_INCLUDES=/usr/local/include/boost-1_33_1/ BOOST_LIBS=/usr/local/lib/

After a while I get following error message:

scons: Building targets ...
g++ -o utils/shapeindex/shapeindex utils/shapeindex/shapeindex.o src/envelope.o plugins/input/shape/shapefile.o -Lagg -Lsrc -L/usr/local/lib -L/usr/lib -L/usr/local/lib -lboost_program_options
utils/shapeindex/shapeindex.o(.text+0x66): In function `main':
: undefined reference to `boost::program_options::options_description:: options_description(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, unsigned int)'
utils/shapeindex/shapeindex.o(.gnu.linkonce.t._ZN5boost 15program_options25basic_command_line_parserIcE7optionsERKNS0_19options_descriptionE+0x11): In function `boost::program_options::basic_command_line_parser<char> ::options(boost::program_options::options_description const&)':
: undefined reference to `boost::program_options::detail::cmdline::set_options_ description(boost::program_options::options_description const&)'
utils/shapeindex/shapeindex.o(.gnu.linkonce.t._ZN5boost15 program_options25basic_command_line_parserIcE10positionalERKNS0_30positional_options_descriptionE+0xf): In function `boost::program_options::basic_command_line_parser<char>:: positional(boost::program_options::positional_options_description const&)':
: undefined reference to `boost::program_options::detail::cmdline::set_positional_ options(boost::program_options::positional_options_description const&)'
utils/shapeindex/shapeindex.o(.gnu.linkonce.t._ZN5boost15 program_options25basic_command_line_parserIcE3runEv+0x30): In function `boost::program_options::basic_command_line_parser<char>::run()':
: undefined reference to `boost::program_options::detail::cmdline::run()'
utils/shapeindex/shapeindex.o(.gnu.linkonce.t._ZN5boost15 program_options25basic_command_line_parserIcEC1EiPPc+0x36): In function `boost::program_options::basic_command_line_parser<char>:: basic_command_line_parser(int, char**)':
: undefined reference to `boost::program_options::detail::cmdline::cmdline(std:: vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&)'
collect2: ld returned 1 exit status
scons: *** [utils/shapeindex/shapeindex] Error 1
scons: building terminated because of errors.

Any idea? Cheers

Ian September 12, 2006 at 12:56 a.m.

Hi,
When I run :
from mapnik import *
as a normal user i get:
ImportError: libmapnik.so: cannot open shared object file: No such file or directory
when i run as root I get:
ImportError: libmapnik.so: symbol png_set_add_alpha, version PNG12_0 not defined in file libpng12.so.0 with link time reference
Ubuntu Dapper 6.06
Any ideas?? I am stuck
thx
Ian

Ian September 12, 2006 at 2:31 p.m.

I solved this by a reboot and then setting:
$export LD_LIBRARY_PATH=/usr/local/lib
and it seems to work ok now

Ian September 12, 2006 at 2:49 p.m.

In Ubuntu to set this automatically so that it is set when you open a terminal for your python prompt,add the lines
export LD_LIBRARY_PATH="/usr/local/lib"
to
/etc/bash.bashrc
this assumes you have installed mapnik to the default $PREFIX mentioned above

artem September 13, 2006 at 10:31 a.m.

Rainer, could you verify you've got boost program_options library on your EL4 box?

jeff February 6, 2007 at 2:31 p.m.

compiles with no problems, demo/rundemo.py works, but this error occurs:

>>> from mapnik import *
>>> registered datasource : shape
File "<stdin>", line 1
registered datasource : shape
^
SyntaxError: invalid syntax

Also unable to get WMS to work using Lighttpd and Python 2.4. From error_log:
jonpy error: NameError
NameError: global name 'Rule' is not defined

artem February 23, 2007 at 8:55 a.m.

Jeff, could you log this into http://trac.mapnik.org ? Or post to mapnik-users.

Nick Whitelegg February 24, 2007 at 10:36 a.m.

Note that libpng >= 1.2.7 is required.

lewis May 3, 2007 at 3:13 p.m.

Does it have a build that can be called from the package manager on Ubuntu?

FreeBSD Porter May 14, 2007 at 5:18 a.m.

has anyone been able to get this to compile on FreeBSD which, like Mapnik, is BSD licensed! :-) ...

FreeBSD Porter May 14, 2007 at 5:20 a.m.

oops I meant like Django :-) (which this site runs on)

gtodd May 14, 2007 at 5:50 p.m.

Re: the above FreeBSD comments. I've been trying for a few releases but there seem to be thread library errors when trying to build on FreeBSD (looking at config.log). As well, scons doesn't seem to adjust for PLATFORM very automagically so the scons build command is pretty long on options :-)

That said it shouldn't be difficult to get this to work: the requisite libraries and applications exist on FreeBSD.

Are other developers/testers using FreeBSD? Let's start adding tickets to trac and see if we can make this go! :-)

cheers

gtodd May 16, 2007 at 5:19 a.m.

I'm unable to test the actual application extensively at present but the build went quite smoothly with scons and the SVN version of mapnik.
Not being familiar with hacking SConstruct files I was unable to do things very elegantly, but adding a check for FreeBSD in uname and appending a link argument was mostly all that was needed to make the build work on FreeBSD:

if env['PLATFORM'] == 'FreeBSD' :
env.Append(LIBS = 'pthread')

Scons seems very nice. Good choice!

One issue is that the current build looks for libraries named boost-[feature]-mt but FreeBSD's boost port/package appears not to add "-mt" to the library name when boost is built with pthreads. I will add a ticket to Trac describing things.

Cheers and keep up the great work!

Artem June 5, 2007 at 11:12 a.m.

Can you run Mapnik after all? I haven't got access to FreeBSD at the momoment but I think your changes to SConstruct are fine. Let me know.

gtodd July 3, 2007 at 7:35 p.m.

Hi Artem,

It seems to run fine after the change but I am not really putting it through its paces. There could be other breakage but I don't think it is FreeBSD/boost specific. At times linux developed applications build fine on FreeBSD and then at runtime threads become an issue. The use of boost should help prevent that :-)

I will keep following up on bug #27:

http://trac.mapnik.org/ticket/27

and will submit a more complete SConstruct patch when I get a bit of time (changed defaults for a number of opts.Add(PathOption) settings).

cheers

conabio November 14, 2007 at 5:59 p.m.

I am trying to compile mapnik with solaris 10, but I'm getting the following exception. What does it mean?
any ide?

n file included from include/mapnik/value.hpp:36,
from include/mapnik/feature.hpp:34,
from include/mapnik/datasource.hpp:37,
from include/mapnik/datasource_cache.hpp:36,
from bindings/python/mapnik_datasource_cache.cpp:26:
include/mapnik/unicode.hpp: In member function `std::wstring mapnik::transcoder::transcode(const std::string&) const':
include/mapnik/unicode.hpp:177: error: conversión inválida de `char**' a `const char**'
include/mapnik/unicode.hpp:177: error: argumento de inicialización 2 de `size_t libiconv(void*, const char**, size_t*, char**, size_t*)'
scons: *** [bindings/python/mapnik_datasource_cache.pic.o] Error 1
scons: building terminated because of errors.

wilsaj November 30, 2007 at 3:35 p.m.

I'm had the same problem, conabio.. I'm trying this from a FreeBSD build.

I'm a bit rusty when it comes to cpp, but I think what the error is trying to say is that the second argument in the iconv() function, &in, is declared a char* and it is expecting a const char*.

On a whim, I changed the line:
char * in = const_cast<char*>(input.data());
to:
const char * in = const_cast<char*>(input.data());

and it compiles now, but I haven't had a chance to look at when and how this gets called. It's probably not the best fix but it might work for you.

thor December 31, 2007 at 9:31 a.m.

Hi,
I tried to build mapnik under Linux (Gentoo). The build goes well if I turn off BINDINGS(=none). The following error messages pop out when I turn on BINDINGS. Any body met the same problem? or any pointers?

Also, if I skip bindings and compile the c++ demo, rundemo produces a seg fault. I have also tried to build it on MinGW, it seems that there are some problems with the 'thread'. I also needed to change the SCons files to make gnu toolchain the preferred one. Anybody succeeded on MinGW (gcc)? thanks a bunch, and happy new year
--error message for binding ------
ld -shared -no_archive -o bindings/python/_mapnik.so bindings/python/mapnik_datasource_cache.os bindings/python/mapnik_image.os bindings/python/mapnik_python.os bindings/python/mapnik_color.os bindings/python/mapnik_polygon_symbolizer.os bindings/python/mapnik_map.os bindings/python/mapnik_stroke.os bindings/python/mapnik_text_symbolizer.os bindings/python/mapnik_polygon_pattern_symbolizer.os bindings/python/mapnik_filter.os bindings/python/mapnik_rule.os bindings/python/mapnik_parameters.os bindings/python/mapnik_shield_symbolizer.os bindings/python/mapnik_datasource.os bindings/python/mapnik_feature.os bindings/python/mapnik_point_symbolizer.os bindings/python/mapnik_image_view.os bindings/python/mapnik_layer.os bindings/python/mapnik_coord.os bindings/python/mapnik_raster_symbolizer.os bindings/python/mapnik_projection.os bindings/python/mapnik_line_pattern_symbolizer.os bindings/python/mapnik_style.os bindings/python/mapnik_line_symbolizer.os bindings/python/mapnik_envelope.os bindings/python/mapnik_featureset.os bindings/python/mapnik_font_engine.os bindings/python/mapnik_query.os -Lagg -Lsrc -L/usr/lib -L/usr/local/lib -lmapnik -lboost_python
ld: cannot find -lmapnik

larry January 8, 2008 at 3:48 a.m.

python scons/scons.py BOOST_INCLUDES=/usr/local/include/boost-1_34_1 BOOST_LIBS=/usr/local/lib
scons: Reading SConscript files ...
Checking for main() in C library m... yes
Checking for main() in C library ltdl... yes
Checking for main() in C library png... yes
Checking for main() in C library tiff... yes
Checking for main() in C library z... yes
Checking for main() in C library jpeg... yes
Checking for main() in C library proj... yes
Checking for main() in C library pq... yes
Checking for main() in C++ library boost_thread... no
Checking for main() in C++ library boost_thread-gcc-mt... no
Could not find header or shared library for boost thread, exiting!

I do have boost installed:
boost-devel-static-1.34.1-5.fc8
boost-devel-1.34.1-5.fc8
boost-1.34.1-5.fc8

larry January 8, 2008 at 9:06 a.m.

# python
Python 2.5.1 (r251:54863, Oct 30 2007, 13:54:11)
[GCC 4.1.2 20070925 (Red Hat 4.1.2-33)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from mapnik import *
>>>

Joseph February 1, 2008 at 3:49 a.m.

ERROR:

/usr/include/boost/python/class.hpp:398: error: no matching function for call to `get_signature(const char* const&, mapnik::Envelope<double>*)'

shonka February 4, 2008 at 8:06 a.m.

I face the same problem as Rainer with Redhat EL4 . Soft linking
cd /usr/local/lib

ln -s libboost_program_options-gcc34.so libboost_program_options.so

ln -s libboost_program_options-gcc34-mt.so libboost_program_options-mt.so

got things compiled. But should I be working with gcc 3.4 for this or do I need to upgrade to 4.1 ?

Artem Pavlenko February 7, 2008 at 10:30 a.m.

mapnik-users list is the best place to discuss and get answers regarding compilations problems etc etc
Thanks

Venkatesh February 22, 2008 at 7:05 a.m.

Has anyone got a complete process of generating maps from Mapnik in windows? I would like to know.

Venkatesh Varalu February 22, 2008 at 7:07 a.m.

If you have got the complete set-up process available for windows...please let me know. I am on a deadline and will greatly appreciate that.

JohnO February 26, 2008 at 3:07 p.m.

Hi All,

Has anyone attempted to build this on the ASUS Eee PC?

Artem Pavlenko February 26, 2008 at 3:38 p.m.

JohnO,
Compiling on Eee should work (assuming you're running Linux) but might take some time due to limited RAM. I wonder if getting packaged version is a better approach.

JohnO February 27, 2008 at 3:17 p.m.

Hi Artem,

I tried installing the Debian 0.5.0 package (the Eee runs a Debian based Xandros Linux and has a deb package manager) but it failed to resolve the dependencies. I'm a linux newbie and got lost at that point. Mapping is a good application for the Eee so I hope some Eee users with some more expertise will take this challenge on soon!

Regards
JohnO

celeo April 14, 2008 at 9:03 p.m.

Hi,

I am having a similar issue as Larry possibly. scons.py finds all the required libs but once it gets to the libboost stuff it cannot find them:

Checking for C++ library boost_filesystem-mt... no
Could not find header or shared library for boost filesystem, exiting!

But I can see it sitting there in /usr/local/lib

I also tried specifically setting the paths with:

scons/scons.py -h BOOST_INCLUDES=/usr/local/include/boost-1_35 BOOST_LIBS=/usr/local/lib

But that doesn't work either. Mac OS X 10.5 Leopard. Python 2.5

Anyone have an idea? I've been searching the web but without significant find. Thank you.

Raj April 17, 2008 at 5:57 p.m.

Try symbolically linking libboost_XX-mt.dylib to libboost_XX-mt.dylib

e.g.,

cd /usr/local/lib
ln -s libboost_filesystem-mt-1_35.dylib libboost_filesystem-mt.dylib

Prabhakar August 8, 2008 at 1:43 p.m.

I am trying to compile Mapnik on Ubuntu 8.04.1 and we ran into problems

scons: Reading SConscript files ...
Building on Linux ...
pkg-config --exists cairomm-1.0
Checking for C library m... yes
Checking for C library ltdl... yes
Checking for C library png... yes
Checking for C library tiff... yes
Checking for C library z... yes
Checking for C library jpeg... yes
Checking for C library proj... yes
Checking for C library pq... no
Checking for C++ library icuuc... no
Could not find header or shared library for icuuc, exiting!

However, I see that icuuc exists on my machine.

/usr/lib/libicuuc.so.38
/usr/lib/libicuuc.so.38.0

Is there a linking problem??
Any suggestions??

Thanks

brainspills August 12, 2008 at 10:15 a.m.

Could be that you don't have a c++ compiler installed. Try installing g++ on your Ubuntu.

wim de vries August 14, 2008 at 2:38 p.m.

After trial and error for a day I got working, I thought. Now I am completely stuck:

Python 2.5.1 (r251:54863, Jan 10 2008, 18:00:49)
[GCC 4.2.1 (SUSE Linux)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from mapnik import *
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib64/python2.5/site-packages/mapnik/__init__.py", line 31, in <module>
from _mapnik import *
ImportError: /usr/local/lib64/libmapnik.so.0.5: undefined symbol: _ZN5boost9call_onceEPFvvERi

Aun Johnsen November 11, 2008 at 12:37 p.m.

I need a MAC toturial, my build fails on icuuc, I have DarwinPort installed, but DarwinPort does not recognize icuuc, I have also no information of what DarwinPort package contains icuuc. Running DarwinPort on Mac OS X Leopard.

Post a comment