Skip to content
Moritz Kobitzsch edited this page Aug 11, 2016 · 128 revisions

General build instructions from source

OSRM source is available via git or source archives, and is built with CMake.

Git

To download from Git, run the following commands:

git clone https://github.com/Project-OSRM/osrm-backend.git
cd osrm-backend

If you would like to build a specific release (optional), you can list the release tags with git tag -l and then checkout a specific tag using git checkout tags/<tag_name>.

Source Release

OSRM can be built from the source archives available on the releases page. Example:

wget https://github.com/Project-OSRM/osrm-backend/archive/vX.Y.Z.tar.gz
tar -xzf vX.Y.Z.tar.gz
cd osrm-backend-X.Y.Z

Building

mkdir -p build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release
cmake --build .
sudo cmake --build . --target install

CMake accepts several optional parameters.

-DCMAKE_BUILD_TYPE=Debug to compile in debug mode. Only needed for development.

-DBUILD_TOOLS=1 to compile any further tools. Usually not needed.

-DENABLE_JSON_LOGGING=1 to add extensive debug logging to JSON responses. Only needed for development.

Red Hat Enterprise Linux, Fedora, or CentOS

See this issue about CentOS/RHEL 6 compiler versions.

See this issue about Fedora and Lua 5.3.

See this page to install osrm-backend on Centos 6.

If compiling on Red Hat Enterprise Linux, Fedora, or CentOS then you will need to enable the EPEL repositories in order to satisfy dependencies.

To compile on Fedora 14 you will need to first install at least the following dependencies:

yum install gcc-c++ libxml2-devel stxxl-devel boost-devel bzip2-devel cmake

To compile on Fedora 15 you will need to first install the following dependencies:

yum install gcc-c++ libxml2-devel stxxl-devel boost-devel boost-regex bzip2-devel libzip-devel

To compile on Fedora 20 you will need to first install the following dependencies:

sudo yum install git cmake gcc-c++

sudo yum install libxml2-devel boost-devel boost-regex bzip2-devel \
     libzip-devel stxxl-devel \
     lua.x86_64 lua-devel.x86_64 luajit.x86_64 luajit-devel.x86_64 \
     luabind.x86_64 luabind-devel.x86_64 expat expat-devel tbb tbb-devel

Finally, follow the installation of Project-OSRM:

git clone https://github.com/DennisOSRM/Project-OSRM.git
mkdir –p Project-OSRM/build
cd Project-OSRM/build
cmake ..
make
sudo make install

To compile on Cent OS 6 / RHEL 6 you will need to first install the following dependencies:

yum install gcc-c++ libxml2-devel boost-devel bzip2-devel cmake

stxxl-devel is not available in the repositories for these distributions a the time of writing, and must be obtained separately. It needs to be manually downloaded, extracted and installed on your system (clear instructions can be found in the stxxl documentation). You then need to specify the location of your stxxl installation when you use cmake using the -DSTXXL_LIBRARY=/somewhere/libstxxl.a flag (see above).

OSRM cannot be compiled on RHEL 5 / CentOS 5 without manually compiling a recent version of libboost.

Debian Squeeze

Debian Squeeze ships with boost 1.42 but 1.44+ is required by OSRM.

I just managed to build OSRM successfully on Debian Squeeze compiling boost-1.53 myself first.

Use g++ >= 4.8 (support for GCC 4.7 was dropped with OSRM release v4.4.0)

Your need to specify your boost location for cmake, e.g.:

   -DBOOST_ROOT=/home/miguel/boost/boost-1.53/lib/

In order to run the binaries I specify the LD_LIBRARY_PATH. Example:

    LD_LIBRARY_PATH=/home/miguel/boost/boost-1.53/lib/ ./osrm-extract  ~/data/osm/germany.osm

Debian Wheezy

There have been reports that compilation has worked on debian "Wheezy".

The last release working on Debian Wheezy without compiling gcc is 4.4.0

To compile on Debian you will probably need to install the following dependencies. (Tested on Debian Wheezy)

sudo apt-get install git libboost-dev gcc g++ make cmake libstxxl-dev \
libxml2-dev libbz2-dev zlib1g-dev libzip-dev libboost-filesystem-dev \
libboost-thread-dev libboost-system-dev libboost-regex-dev libboost-program-options-dev \
libboost-iostreams-dev libgomp1 \
liblua5.1-0-dev libluabind-dev pkg-config libtbb-dev libboost-test-dev \
libprotobuf-dev libosmpbf-dev

In addition, you need a more recent CMake version (2.8.11+).

Debian Jessie

Use the following command to install the dependencies (git is used to fetch the source):

sudo apt-get install git g++ cmake libboost-dev libboost-filesystem-dev libboost-thread-dev \
libboost-system-dev libboost-regex-dev libstxxl-dev libxml2-dev libsparsehash-dev libbz2-dev \
zlib1g-dev libzip-dev libgomp1 liblua5.1-0-dev \
libluabind-dev pkg-config libgdal-dev libboost-program-options-dev libboost-iostreams-dev \
libboost-test-dev libtbb-dev libexpat1-dev

###Ubuntu

Building on Ubuntu

Mac OS X 10.7.1, 10.8.2

To compile the source on a Mac, please install the homebrew package system. It will provide all necessary dependencies:

brew install boost git cmake libzip libstxxl libxml2 lua51 luajit luabind tbb ccache

If you run into problems with luabind while compiling, make sure you have only Lua 5.1 and not Lua 5.2 installed on your system:

brew uninstall lua

To be able to compile tools:

brew install GDAL

SLES 11 SP3

save following as script and run:

    #!/bin/bash

    OS=$(uname)
    ARCH=$(uname -m)
    PREFIX=/opt/osrm_infrastructure

    mkdir packages 2> /dev/null
    cd packages

    wget http://www.cmake.org/files/v2.8/cmake-2.8.12.2.tar.gz
    wget https://protobuf.googlecode.com/files/protobuf-2.5.0.tar.bz2
    wget http://sourceforge.net/projects/luabind/files/luabind/0.9.1/luabind-0.9.1.tar.gz
    wget http://sourceforge.net/projects/stxxl/files/stxxl/1.3.1/stxxl-1.3.1.tar.gz
    wget http://sourceforge.net/projects/boost/files/boost/1.55.0/boost_1_55_0.tar.bz2
    wget http://luajit.org/download/LuaJIT-2.0.2.tar.gz
    git clone https://github.com/scrosby/OSM-binary.git OSM-binary.git
    wget -O Project-OSRM-0.3.7.zip https://github.com/DennisOSRM/Project-OSRM/archive/v0.3.7.zip

    cd ..

    function run() {
       CMD=$1

       eval $CMD
       if [[ $? -ne 0 ]]; then
          echo "CMD: '$CMD' Failed"
          exit 1
       fi
       echo "CMD: '$CMD' ... Success"
    }

    DIR=$(pwd)

    if [[ ! -d ${PREFIX} ]]; then
       echo "Dir: '${PREFIX}' does not exist"
       run "mkdir ${PREFIX} 2>/dev/null"
    fi

    if [[ ! -w ${PREFIX} ]]; then
       echo "Couldn't write to: '${PREFIX}'"
       exit 1
    fi

    NAME="cmake-2.8.12.2"
    run "cd /tmp"
    rm -rf /tmp/$NAME
    run "tar -zxf $DIR/packages/${NAME}.tar.gz"
    run "cd $NAME"
    run "./configure --prefix=$PREFIX"
    run "make -j4"
    run "make install"

    NAME="protobuf-2.5.0"
    run "cd /tmp"
    rm -rf /tmp/$NAME
    run "tar -jxf $DIR/packages/${NAME}.tar.bz2"
    run "cd $NAME"
    run "./configure --prefix=$PREFIX/$NAME"
    run "make -j4"
    run "make install"

    NAME="boost_1_55_0"
    run "cd /tmp"
    rm -rf /tmp/$NAME
    run "tar -jxf $DIR/packages/${NAME}.tar.bz2"
    run "cd $NAME"
    run "./bootstrap.sh --prefix=$PREFIX/$NAME"
    run "./b2 install --prefix=$PREFIX/$NAME"

    NAME="stxxl-1.3.1"
    run "cd /tmp"
    rm -rf /tmp/$NAME
    run "tar -zxf $DIR/packages/${NAME}.tar.gz"
    run "cd $NAME"
    run "make library_g++"
    run "mkdir -p $PREFIX/$NAME"
    run "cp -r /tmp/$NAME/lib $PREFIX/$NAME/"
    run "cp -r /tmp/$NAME/include $PREFIX/$NAME/include"

    export BOOST_ROOT=/tmp/boost_1_55_0

    NAME="luabind-0.9.1"
    run "cd /tmp"
    rm -rf /tmp/$NAME
    run "tar -zxf $DIR/packages/${NAME}.tar.gz"
    run "cd $NAME"
    # Boost rule doesn't look in lib64 by default
    run "sed -i 's|(prefix)/lib ;|(prefix)/lib64 ;|' Jamroot"
    run "/tmp/boost_1_55_0/bjam --prefix=$PREFIX/$NAME install"

    NAME="LuaJIT-2.0.2"
    run "cd /tmp"
    rm -rf /tmp/$NAME
    run "tar -zxf $DIR/packages/${NAME}.tar.gz"
    run "cd $NAME"
    run "sed -i 's|PREFIX=.*/usr/local|PREFIX=$PREFIX/$NAME|' Makefile"
    run "make install"

    export PATH=$PREFIX/bin:$PREFIX/protobuf-2.5.0/bin:$PATH

    NAME="OSM-binary"
    run "cd /tmp"
    rm -rf /tmp/$NAME
    run "mkdir -p /tmp/$NAME"
    run "cp -r $DIR/packages/${NAME}.git/* /tmp/$NAME/"
    run "cd $NAME"
    run "cmake -DPROTOBUF_LIBRARY=$PREFIX/protobuf-2.5.0/lib/libprotobuf.so -DPROTOBUF_LITE_LIBRARY=$PREFIX/protobuf-2.5.0/lib/libprotobuf-lite.so -DPROTOBUF_INCLUDE_DIR=$PREFIX/protobuf-2.5.0/include -DCMAKE_INSTALL_PREFIX=$PREFIX/$NAME ."
    run "make install"

    NAME="Project-OSRM-0.3.7"
    run "cd /tmp"
    rm -rf /tmp/$NAME
    run "unzip $DIR/packages/${NAME}.zip"
    if [[ -n $NAME ]]; then
       rm -rf $PREFIX/$NAME
    fi
    run "mkdir -p /opt/$NAME"
    run "cd /opt/$NAME"
    run "sed -i 's| -pedantic||' /tmp/$NAME/CMakeLists.txt"
    run "cmake -DBOOST_LIBRARYDIR=$PREFIX/boost_1_55_0/lib -DLUABIND_LIBRARIES=$PREFIX/luabind-0.9.1/lib -DLUABIND_LIBRARY=$PREFIX/luabind-0.9.1/lib/libluabindd.so -DLUABIND_INCLUDE_DIR=$PREFIX/luabind-0.9.1/include -DSTXXL_LIBRARY=$PREFIX/stxxl-1.3.1/lib/libstxxl.a -DSTXXL_INCLUDE_DIR=$PREFIX/stxxl-1.3.1/include -DLUAJIT_LIBRARIES=$PREFIX/LuaJIT-2.0.2/lib -DLUAJIT_INCLUDE_DIR=$PREFIX/LuaJIT-2.0.2/include -DPROTOBUF_LIBRARY=$PREFIX/protobuf-2.5.0/lib/libprotobuf.so -DPROTOBUF_INCLUDE_DIR=$PREFIX/protobuf-2.5.0/include -DOSMPBF_LIBRARY=$PREFIX/OSM-binary/lib/libosmpbf.a -DOSMPBF_INCLUDE_DIR=$PREFIX/OSM-binary/include /tmp/${NAME}/"
    run "make"

Windows

Windows Compilation

Centos 7 64 Bit

    yum install epel-release
    yum install wget
    yum install  libxml2-devel boost-devel boost-regex bzip2-devel \
         libzip-devel  protobuf-devel protobuf-lite protobuf-lite-devel \
          lua-devel.x86_64 cmake boost-build boost-jam tbb-devel
    yum install patch openmpi

INSTALL STXXL

    cd /tmp
    git clone http://github.com/stxxl/stxxl.git
    cd stxxl
    mkdir debug
    cd debug
    cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=/opt/osrm_infrastructure/stxx -DBUILD_STATIC_LIBS=ON ..
    make -j4 && make install

    cd..
    mkdir release; cd release
    cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/opt/osrm_infrastructure/stxx - DBUILD_STATIC_LIBS=ON  ..
    make -j4 && make install  

LUABIND

    cd /tmp
    wget http://sourceforge.net/projects/luabind/files/luabind/0.9.1/luabind-0.9.1.tar.gz
    tar -zxvf luabind-0.9.1.tar.gz 
    cd luabind-0.9.1/

Need to modify line 84 of Jamroot to use lib64 instead of lib

    vi Jamroot

:84

Change this line local lib = $(prefix)/lib ;
to look like this: local lib = $(prefix)/lib64 ;

    git clone https://gist.github.com/2011636.git
    patch -p1 < ./2011636/luabind_boost.patch
    bjam install --prefix=/opt/osrm_infrastructure/luabind-0.9.1

LUAJit

    cd /tmp
    wget http://luajit.org/download/LuaJIT-2.0.2.tar.gz
    tar -zxvf LuaJIT-2.0.2.tar.gz
    cd LuaJIT-2.0.2
    make install PREFIX=/opt/osrm_infrastructure/LuaJIT-2.0.2

OSM BINARY

    cd /tmp
    git clone https://github.com/scrosby/OSM-binary.git
    cd OSM-binary
    mkdir build
    cd build
    cmake ..
    make
    make install

OSRM

    cd /opt
    wget -O Project-OSRM-0.3.7.zip https://github.com/DennisOSRM/Project-OSRM/archive/v0.3.7.zip
    unzip v0.3.7.zip
    cd osrm-backend
    sed -i 's| -pedantic||' CMakeLists.txt
    mkdir build; cd build
    cmake  -DLUABIND_INCLUDE_DIR=/opt/osrm_infrastructure/luabind-0.9.1/include -DLUABIND_LIBRARY=/opt/osrm_infrastructure/luabind-0.9.1/lib/libluabindd.so \
   -DLUAJIT_LIBRARIES=/opt/osrm_infrastructure/LuaJIT-2.0.2/lib/libluajit-5.1.so -DLUAJIT_INCLUDE_DIR=/opt/osrm_infrastructure/LuaJIT-2.0.2/include/ \
   -DSTXXL_LIBRARY=/opt/osrm_infrastructure/stxx/lib/libstxxl.a -DSTXXL_INCLUDE_DIR=/opt/osrm_infrastructure/stxx/include  -DOSMPBF_LIBRARY=/usr/local/lib/libosmpbf.a -DOSMPBF_INCLUDE_DIR=/usr/local/include/ -DBOOST_LIBRARYDIR=/usr/lib64 ..