Skip to content

Windows Compilation

Delawen edited this page May 18, 2012 · 22 revisions

Compiling OSRM on Windows is not straight forward right now. This steps lead us to a correct OSRM compilation and running over Windows 7, but cannot warrantee you anything.

Use always a 64bit version, because 32bit versions will lack of RAM too easily and throw weird errors.

Prerequisites

  • x64 Windows machine
  • Microsoft Visual Studio 2008 Professional Edition with x64 compiler installed or Microsoft Visual Studio 2008 Express Edition (only from x32 builds)

Compilation Steps


*** vsprojects[\x64]\Release mean vsprojects\Release or vsprojects\x64\Release depending on choosen platform ***


  1. Download and extract the content DennisOSRM-Project-OSRM-v0.3b-0-gcaf9086.tar.gz to a folder in computer (Ex: C:\Osrm)
  2. Create a folder named lib in Osrm folder (Ex: C:\Osrm\lib)
  3. Download and extract the content of boost_1_49_0.zip to boost dir from lib (Ex: C:\Osrm\lib\boost)

compling boost library

*** for x32 run in boost dir from a cmd prompt: bootstratp b2 --build-type=complete

*** for x64 run in boost dir from a cmd prompt: boostrap bjam --toolset=msvc-9.0 address-model=64 --build-type=complete stage

this compilation will take a long time to finish and will add another 5-7 GB of data to boost folder

  1. Download and extract the content of bzip2-1.0.6.tar.gz to bzip2 dir from lib (Ex: C:\Osrm\lib\bzip2

compiling bzip2 library

*** for x32 just open libbz2.dsp and convert to libbz2.sln and build using release version. *** for x64 open libbz2.dsp and convert to libbz2.sln and choose a new configuration based on release version of x32 but at target processor choose x64 ("Build" menu -> "Configuration Manager": "Active solutions configuration" -> "Release" and "Active solution platform" -> "New" -> "Type or select the new platform" -> "x64" also "Copy settings from" -> "Win32", check "Create new project platforms") After rebuilding make 3 folders in bzip2 dir named bin, lib and include Copy libbz2.dll from bzip2 folder in bzip2\bin Copy libbz.lib from bzip2\Release folder in bzip2\lib Copy bzlib.h from bzip2 folder in bzip2\include

  1. Download and extract the content of protobuf-2.4.1.zip to protobuf folder from lib (Ex: C:\Osrm\lib\protobuf)

compiling protobuf library

*** for x32 just open protobuf.sln from vsprojects and build using release version. Build and after fail (will fail for sure) download protoc-2.4.1-win32.zip and copy protoc.exe in vsprojects\Release, rebild the project (now you will have some fails but the library is compiled) *** for x64 open protobuf.sln from vsprojects and choose a new configuration based on release version of x32 but at target processor choose x64 ("Build" menu -> "Configuration Manager": "Active solutions configuration" -> "Release" and "Active solution platform" -> "New" -> "Type or select the new platform" -> "x64" also "Copy settings from" -> "Win32", check "Create new project platforms") Rebuild and after fail (will fail for sure) download protoc-2.4.1-win32.zip and copy protoc.exe in vsprojects[\x64]\Release and rebuild the project (now you will have some fails but the library is compiled) after second rebuild run extract_includes.bat from vsprojects folder (this will create the include folder in vsprojects) Make 3 folders in protobuf named bin, lib and include Copy protoc.exe from protobuf\vsprojects[\x64]\Release to protobuf\bin Copy the content of include folder from protobuf\vsprojects\include to protobuf\include Copy *.lib from protobuf\vsprojects[\x64]\Release in protobuf\lib

  1. Download and extract the content of sparsehash-2.0.2.zip to sparsehash folder from lib (Ex: C:\Osrm\lib\sparsehash) compiling sparsehash library ============================ *** for x32 just open sparsehash.sln and rebuild using release version *** for x64 open sparsehash.sln and choose a new configuration based on release version of x32 but at target processor choose x64 ("Build" menu -> "Configuration Manager": "Active solutions configuration" -> "Release" and "Active solution platform" -> "New" -> "Type or select the new platform" -> "x64" also "Copy settings from" -> "Win32", check "Create new project platforms") Rebuild solution.

  2. Download and extract the content of stxxl-1.3.1.zip to stxxl folder from lib (Ex: C:\Osrm\lib\stxxl)

compiling stxxl library

*** Create a file named make.settings.local in stxxl folder with folowing content: BOOST_ROOT = "$(TOPDIR)..\boost"#

*** Add /LIBPATH:$(BOOST_ROOT)\stage\lib
in make.settings.msvc between /LIBPATH:$(BOOST_ROOT)\lib\ and /STACK:16777216 /NOLOGO (line 68) so this line become /LIBPATH:$(BOOST_ROOT)\lib\ /LIBPATH:$(BOOST_ROOT)\stage\lib\ /STACK:16777216 /NOLOGO

*** If you compile for debug you need to add DEBUG_COMPILER=/MDd /Zi and DEBUG_LINKER=/DEBUG to make.settings.local

*** for x32 just open stxxl.sln and rebuild using "Library" *** for x64 open stxxl.sln and choose a new configuration based on x32 Library but at target processor choose x64 ("Build" menu -> "Configuration Manager": "Active solutions configuration" -> "Library" and "Active solution platform" -> "New" -> "Type or select the new platform" -> "x64" also "Copy settings from" -> "Win32", check "Create new project platforms") Rebuild solution.

  1. Download and extract the content of zlib-1.2.7.tar.gz to zlib folder from lib (Ex: C:\Osrm\lib\zlib)

compiling zlib library

*** for x32 download and install masm32 Open a cmd promt and go to zlib\contrib\masmx86 folder Add C:\masm32\bin to path (SET path=C:\masm32\bin;%path%) Run bld_ml32.bat from zlib\contrib\masmx86 folder Go to root zlib folder and run "c:\Program Files\Microsoft Visual Studio 9.0\VC\vcpackages\vcbuild.exe" /rebuild contrib\vstudio\vc9\zlibvc.sln "Release|Win32" Create 3 folders in zlib named bin, lib and include copy zlib\contrib\vstudio\vc9\x86\ZlibDllRelease\zlibwapi.dll to zlib\bin\zlib.dll copy zlib\zconf.h to zlib\include\zconf.h copy zlib\zlib.h to zlib\inc\zlib.h copy zlib\contrib\vstudio\vc9\x86\ZlibDllRelease\zlibwapi.lib to zlib\lib\zlib.lib

*** for x64 Open a cmd promt and go to zlib\contrib\masmx64 folder add C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\bin\x86_amd64 to path (SET path=C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\bin\x86_amd64;%path%) Run bld_ml64.bat from zlib\contrib\masmx64 folder Open zlibvc.sln from zlib\contrib\vstudio\vc9 folder and choose a Release version with 64 bits from build -> configuration manager Rebuid the solution. Create 3 folders in zlib named bin, lib and include copy zlib\contrib\vstudio\vc9\x64\ZlibDllRelease\zlibwapi.dll to zlib\bin\zlibwapi.dll copy zlib\zconf.h to zlib\include\zconf.h copy zlib\zlib.h to zlib\inc\zlib.h copy zlib\contrib\vstudio\vc9\x64\ZlibDllRelease\zlibwapi.lib to zlib\lib\zlib.lib

*** for x64 -> Look for a precompiled version of libxml2 (libxml2_x64.zip from project files) for x64 (usually from a x64 apache install) download the dll and extract the exported symbols to a def file (look at http://www.coderetard.com/2009/01/21/generate-a-lib-from-a-dll-with-visual-studio/ for more info) for lib program use /machine:x64 option Download the libxml2-2.7.8.win32.zip file. Make a folder named libxml2 and make in this 3 new subfolders named bin, lib and include. Copy in libxml2\bin the downloaded dll (libxml2.dll) Copy in libxml2\lib the created import library (libxml2.lib) Copy in libxml2\include the libxml folder from libxml2-2.7.8.win32.zip\include

*** for x32 you will find precompiled library (file libxml2-2.7.8.win32.zip)

  1. Download and extract the libiconv-1.14.tar.gz to libiconv folder from lib (Ex: C:\Osrm\lib\libiconv) Use http://www.codeproject.com/Articles/302012/How-to-Build-libiconv-with-Microsoft-Visual-Studio as a guide for building a project for iconv (libiconv_vcproject.zip from project files) *** for x64 open libiconv.sln from libiconv\libiconv folder and choose a new configuration based on release version of x32 but at target processor choose x64 ("Build" menu -> "Configuration Manager": "Active solutions configuration" -> "Release" and "Active solution platform" -> "New" -> "Type or select the new platform" -> "x64" also "Copy settings from" -> "Win32", check "Create new project platforms") After rebuild create a folder named iconv in lib (Ex: C:\Osrm\lib\iconv) Create 3 new folders in iconv named bin, lib and include Copy libiconv.dll from libiconv\libiconv\x64\Release to iconv\bin Copy libiconv.lib from libiconv\libiconv\x64\Release to iconv\lib Copy content of libiconv\libiconv\include in iconv\bin *** for x32 you can find precompiled version of the lib (libiconv-1.9.2-1-bin.zip and libiconv-1.9.2-1-lib.zip)

  2. Edit osrm.vsprops from Osrm\vcprojects adjusting paths to indicate the folders from lib dir

  3. *** for x64 open osrm.sln from Osrm\vcprojects and choose a new configuration based on release version of x32 but at target processor choose x64 ("Build" menu -> "Configuration Manager": "Active solutions configuration" -> "Release" and "Active solution platform" -> "New" -> "Type or select the new platform" -> "x64" also "Copy settings from" -> "Win32", check "Create new project platforms") Rebuild solution.

  4. Build of createHierachy.exe *** Modify Osrm\DataStructures\NNGrid.h and add #undef min #undef max before "static const unsigned MAX_CACHE_ELEMENTS = 1000;" (line 51)

*** comment line 51 "#define DELETE(x) do { if(NULL != x) { delete x; x = NULL; } }while(0);" from Osrm\typedefs.h

*** Replace DELETE(s); from Osrm\routed.cpp line 134 with do { if(NULL != s) { delete s; s = NULL; } }while(0); and DELETE(objects); from line 135 with do { if(NULL != objects) { delete objects; objects = NULL; } }while(0);

*** Replace DELETE(edgeBasedGraphFactory); from Osrm\createHierarchy.cpp line 143 with do { if(NULL != edgeBasedGraphFactory) { delete edgeBasedGraphFactory; edgeBasedGraphFactory = NULL; } }while(0); and DELETE( writeableGrid ); from line 148 with do { if(NULL != writeableGrid) { delete writeableGrid; writeableGrid = NULL; } }while(0); and DELETE( cleanup ); from line 178 with do { if(NULL != cleanup) { delete cleanup; cleanup = NULL; } }while(0);

*** Comment or delete "typename" from Osrm\Contractor\EdgeBasedGraphFactory.cpp line 42 for ( /typename/ std::vector< NodeBasedEdge >::const_iterator i = ...

*** In Osrm\Contractor\EdgeBasedGraphFactory.cpp change line 105 from "while(restrictionIterator->fromNode < u && inputRestrictions.end() != restrictionIterator) {" to while(inputRestrictions.end() != restrictionIterator && restrictionIterator->fromNode < u) { line 117 from "if(u == restrictionIterator->fromNode) {" to if(inputRestrictions.end() != restrictionIterator && u == restrictionIterator->fromNode) { line 120 from "if(v == secondRestrictionIterator->viaNode && w == secondRestrictionIterator->toNode) {" to if(inputRestrictions.end() != secondRestrictionIterator && v == secondRestrictionIterator->viaNode && w == secondRestrictionIterator->toNode) { line 124 from "} while(u == secondRestrictionIterator->fromNode);" to } while(inputRestrictions.end() != secondRestrictionIterator && u == secondRestrictionIterator->fromNode);

*** Remove inline definition of gettimeofday from Osrm\DataStructures\Util.h line 36 adding this function in a new file named Util.cpp in the same folder void gettimeofday(struct timeval* t,void* timezone); in header and #include "Util.h" void gettimeofday(struct timeval* t,void* timezone) {
struct _timeb timebuffer; _ftime( &timebuffer ); t->tv_sec=timebuffer.time; t->tv_usec=1000*timebuffer.millitm; } in cpp

*** Add Osrm\DataStructures\Util.cpp and Osrm\Contractor\EdgeBasedGraphFactory.cpp to project (add existing file)

*** Add $(BoostPath)\stage\lib in project properties -> linker -> General -> Additional library directories

Rebuild project.

  1. Build of extractor.exe *** Add DataStructures\Util.cpp to project *** Add $(BoostPath)\stage\lib in project properties -> linker -> General -> Additional library directories Rebuild project.

  2. Build of routed.exe

*** Replace DELETE( tempPointer ); from Osrm\Server\RequestHandler.h line 47 with do { if(NULL != tempPointer) { delete tempPointer; tempPointer = NULL; } }while(0);

*** Replace DELETE( searchEngine ); from Osrm\Plugins\ViaRoutePlugin.h line 68 with do { if(NULL != searchEngine) { delete searchEngine; searchEngine = NULL; } }while(0); and DELETE( desc ); from line 268 with do { if(NULL != desc) { delete desc; desc = NULL; } }while(0);

*** Add Osrm\Descriptors\DescriptionFactory.cpp to project

*** Add $(BoostPath)\stage\lib in project properties -> linker -> General -> Additional library directories

Rebuild project.

Final steps

Copy libxml2.dll from Osrm\lib\libxml2\bin to exe folder (Osrm\vcprojects\x64\Release) Copy zlibwapi.dll from Osrm\lib\zlib\bin to exe folder (Osrm\vcprojects\x64\Release) Change server.ini from Osrm\vcprojects\x64\Release folder to indicate at correct files Modify Osrm\Docs\WebFrontend\Route.js line 32 to use local server for test

On server you will need to run "Microsoft Visual C++ 2008 Redistributable SP1" (vcredist_x64.exe from project files)

Kudos to pixecs, who did a great job.