pgRouting on Mac OS X 10.6.8

Some notes about how to build pgRouting on Mac OS X, in case I have to do this again in the future. 🙂 I’m writing this from my memory and I hope I did not forget something, but it should work similar to what I’ve described.

pgRouting adds geospatial routing functionality to a PostGIS / PostgreSQL geospatial database. So, as a preliminary requirement, we have to start with installing PostgreSQL and PostGIS.

I’ve done this using MacPorts, so

$ sudo port -d install postgresql90 postgresql90-server postgis

If you like, you can also install pgAdmin3 via MacPorts, an administration program to PostgreSQL

To create a database instance, after install do

$ sudo mkdir -p /opt/local/var/db/postgresql90/defaultdb
$ sudo chown postgres:postgres /opt/local/var/db/postgresql90/defaultdb
$ sudo su postgres -c '/opt/local/lib/postgresql90/bin/initdb -D /opt/local/var/db/postgresql90/defaultdb'

When executing the last command from above, I remember I had some trouble with the postgres user that was created during installation. Check that the postgres user account can be executed using the su command, e.g.

$ sudo su - postgres

If not, make sure that the postgres account has a valid shell

$ sudo dscl . -create /Users/postgres UserShell /bin/sh

Note that the installation has created a startup item for starting postgresql90-server with launchd. It is disabled by default. Execute the following command to start the server, and to cause the server to launch at startup:

$ sudo port load postgresql90-server

As an alternative to launchd, you can also start the database server using:

$ /opt/local/lib/postgresql90/bin/postgres -D /opt/local/var/db/postgresql90/defaultdb

or

$ /opt/local/lib/postgresql90/bin/pg_ctl -D /opt/local/var/db/postgresql90/defaultdb -l logfile start

After starting the server, you might want to look at /opt/local/var/log/postgresql90/postgres.log to check if the server is running OK.

Now, let’s try to install pgRouting.

The pgRouting package is also available from MacPorts, but only an older version 1.03. So, I just went to www.pgrouting.org and downloaded the latest source package pgrouting-1.05.tar.gz from 2010/11/22.

However, you won’t be available to successfully build from this archive (at least not on Mac OS X…)! Instead, you will end up with a couple of “undefined symbols” when linking.

For solving this, go to the pgRouting GitHub repository instead. This issue explains the cause why the linking fails on Mac OS X. Fortunately, this issue has already been fixed, so download a current snapshot from the repository and try to build this one instead.

First, you need to edit cmake/FindPostgreSQL.cmake. Add the include path /opt/local/include/postgresql90/server
and the library path /opt/local/lib/postgresql90 to the file so that cmake is able to locate your PostgreSQL installation.

Then build pgRouting with

$ cmake .
$ make
$ sudo make install

You should end up with something like this

[100%] Built target routing
Install the project...
-- Install configuration: ""
-- Installing: /opt/local/lib/postgresql90/librouting.so
-- Installing: /usr/share/pgrouting/routing_core.sql
-- Installing: /usr/share/pgrouting/routing_core_wrappers.sql
-- Installing: /usr/share/pgrouting/routing_topology.sql
-- Installing: /usr/share/pgrouting/matching.sql

Finally, I hope my memory still serves me right:

$ createdb -U postgres -E utf8 template_postgis
$ psql -U postgres -d template_postgis -f /opt/local/share/postgresql90/contrib/postgis-1.5/postgis.sql 
$ psql -U postgres -d template_postgis -f /opt/local/share/postgresql90/contrib/postgis-1.5/spatial_ref_sys.sql 
$ psql -U postgres -d template_postgis -f /usr/share/pgrouting/routing_core.sql 
$ psql -U postgres -d template_postgis -f /usr/share/pgrouting/routing_core_wrappers.sql 
$ psql -U postgres -d template_postgis -f /usr/share/pgrouting/routing_topology.sql 

Create a pgRouting enabled database using the new template_postgis template

$ createdb -U postgres -T template_postgis routing

That’s it! If you are new to pgRouting, you can find a good example about route calculation using pgRouting here.

10 thoughts on “pgRouting on Mac OS X 10.6.8”

    1. Hi charlax – “brew install pgrouting” does not work for me. I get
      “Error: No available formula for pgrouting”.

      After entering “brew search” into the Terminal, I do not see pgRouting listed. Let me know if I’m doing something wrong. Thanks, Kevin

  1. I’ve got an error when i enter a make command.
    How to fix it?

    ———————

    sudo make
    Scanning dependencies of target routing
    [ 16%] Building C object core/src/CMakeFiles/routing.dir/dijkstra.o
    i686-apple-darwin11-llvm-gcc-4.2: -lgmp: linker input file unused because linking not done
    [ 33%] Building C object core/src/CMakeFiles/routing.dir/astar.o
    i686-apple-darwin11-llvm-gcc-4.2: -lgmp: linker input file unused because linking not done
    [ 50%] Building C object core/src/CMakeFiles/routing.dir/shooting_star.o
    i686-apple-darwin11-llvm-gcc-4.2: -lgmp: linker input file unused because linking not done
    [ 66%] Building CXX object core/src/CMakeFiles/routing.dir/boost_wrapper.o
    i686-apple-darwin11-llvm-g++-4.2: -lgmp: linker input file unused because linking not done
    [ 83%] Building CXX object core/src/CMakeFiles/routing.dir/astar_boost_wrapper.o
    i686-apple-darwin11-llvm-g++-4.2: -lgmp: linker input file unused because linking not done
    [100%] Building CXX object core/src/CMakeFiles/routing.dir/shooting_star_boost_wrapper.o
    In file included from /opt/distr/pgrouting/lastsrc/pgRouting-pgrouting-a0c6c18/core/src/shooting_star_search.hpp:28,
    from /opt/distr/pgrouting/lastsrc/pgRouting-pgrouting-a0c6c18/core/src/shooting_star_boost_wrapper.cpp:27:
    /opt/distr/pgrouting/lastsrc/pgRouting-pgrouting-a0c6c18/core/src/edge_visitors.hpp:9:42: error: boost/graph/detail/is_same.hpp: No such file or directory
    make[2]: *** [core/src/CMakeFiles/routing.dir/shooting_star_boost_wrapper.o] Error 1
    make[1]: *** [core/src/CMakeFiles/routing.dir/all] Error 2
    make: *** [all] Error 2

  2. Hi it helped me a lot! thank you. I had to create separately user and group. I am newbie in programming. Can you please tell me the syntax and how to write the ‘First, you need to edit cmake/FindPostgreSQL.cmake. Add the include path /opt/local/include/postgresql90/server
    and the library path /opt/local/lib/postgresql90 to the file so that cmake is able to locate your Post­greSQL installation.’?
    thank you
    christina

    1. Just add the line /opt/local/include/postgresql90/server to the list of directories underneath FIND_PATH(POSTGRESQL_INCLUDE_DIR postgres.h, and the line /opt/local/lib/postgresql90 underneath find_library(POSTGRESQL_LIBRARIES NAMES pq libpq.

        1. Hi Dirk,

          I tried to install pgrouting on another machine.
          When i run
          ‘sudo make install’
          I take
          ‘make: *** No rule to make target `install’. Stop.’

          Do you have any suggestion?

          Thanks
          christina

  3. Unfortunately not. I am searching for a solution. If I will have sth new I ‘ll let you know.
    Thanks anyway!
    christina:)

Leave a Reply