Installing PostGIS 0.8.0 on Mac OS 10.3.2

PostGIS runs on top of the PostgreSQL and adds support for geographic objects to the object-relational database.

Installing the latest PostGIS Release on Mac OS 10.3.2 can be tricky, so I summed up the main steps I did to get PostGIS up and running on my machine.

Since my unix knowledge is very limited I have to thank the PostGIS Listers, Rich Kilmer, Entropy.ch and Nona.net for their very helpful hints.Basically you need to follow those 6 steps:

- Install GNU GCC 3.4
- Install Readline 4.3 (for readline support in PostgreSQL)
- Install PostgreSQL 7.4
- Install PROJ.4
- Install GEOS 1.0.0
- Install PostGIS 0.8.0

Install GNU GCC 3.4

Download the sources from one of the mirrors.
Read the installation instructions twice.
Configure and install GCC 3.4.

/usr/local/src user$ tar -xf gcc-3.4-20031217.tar
/usr/local/src user$ cd gcc-3.4-20031217
/usr/local/src user$ mkdir /usr/local/gcc-3.4
/usr/local/src user$ cd /usr/local/gcc-3.4
/usr/local/gcc-3.4 user$ /usr/local/src/gcc-3.4-20031217/configure --prefix=/usr/local/gcc-3.4 --enable-shared=libstdc++ --enable-languages=c++
/usr/local/gcc-3.4 user$ make
/usr/local/gcc-3.4 user$ sudo make install
[enter the su password]

After GCC 3.4 is built you have to modify the file /usr/include/mach-o/dyld.h:

add the line
#define __private_extern__ extern
just above the block
#if defined(__MWERKS__) && !defined(__private_extern__)
#define __private_extern__ __declspec(private_extern)
#endif

To use GCC 3.4 I backed up the Apple original GCC binaries in /usr/bin and created symlinks (ln -s) from the binaries in /usr/local/gcc-3.4/bin to /usr/bin. Maybe there is an easier way to switch between GCC versions (e.g. by editing gcc_select), but my way did the trick too.

Install Readline 4.3

/usr/local/src user$ curl -o readline-4.3.tar.gz ftp://ftp.gnu.org/gnu/readline/readline-4.3.tar.gz
/usr/local/src user$ tar -xzf readline-4.3.tar.gz
/usr/local/src user$ cd readline-4.3
/usr/local/src/readline-4.3 user$ perl -i.bak -p -e "s/SHLIB_LIBS=.*/SHLIB_LIBS='-lSystem -lncurses -lcc_dynamic'/g" support/shobj-conf
/usr/local/src/readline-4.3 user$ ./configure
/usr/local/src/readline-4.3 user$ make
/usr/local/src/readline-4.3 user$ sudo make install
[enter the su password]

Install PostgreSQL 7.4

Download the sources from one of the mirrors.
Read the documentation.
Configure and install PostgreSQL.

/usr/local/src user$ tar -xzf postgresql-7.4.tar.gz
/usr/local/src user$ cd postgresql-7.4
/usr/local/src/postgresql-7.4 user$ LDFLAGS=-lstdc++ ./configure --bindir=/usr/local/bin --mandir=/usr/local/share/man/ --enable-recode --with-CXX --enable-odbc --enable-syslog --enable-unicode-conversion --enable-multibyte

[Note: this is my configuration, important is not to forget to set LDFLAGS=-lstdc++]

/usr/local/src/postgresql-7.4 user$ make
/usr/local/src/postgresql-7.4 user$ sudo make install
[enter the su password]

Create a new user in the Users System Preferences Pane:
Name: PostgreSQL User
Short Name: postgres
Password: whatever you want

/usr/local/src/postgresql-7.4 user$ sudo chown -R postgres /usr/local/pgsql/
/usr/local/src/postgresql-7.4 user$ su - postgres
[enter the postgres password]
~ postgres$ /usr/local/bin/initdb -D /usr/local/pgsql/data
~ postgres$ usr/local/bin/pg_ctl -D /usr/local/pgsql/data -l /usr/local/pgsql/data/postgres.log
start ~ postgres$ /usr/local/bin/createdb test1
~ postgres$ /usr/local/bin/psql test1

Install PROJ.4

Download the source.
Configure and install PROJ.4.

/usr/local/src user$ tar -xzf proj-4.4.7.tar.gz
/usr/local/src user$ cd proj-4.4.7
/usr/local/src/proj-4.4.7 user$ ./configure
/usr/local/src/proj-4.4.7 user$ make
/usr/local/src/proj-4.4.7 user$ sudo make install
[enter the su password]

Test your installation by running the command:

~ user$ proj

If your installation was successful the output should be something like:

Rel. 4.4.7, 31 March 2003
usage: proj [ -beEfiIlormsStTvVwW [args] ] [ +opts[=arg] ] [ files ]

Install GEOS 1.0.0

Download the source.
Configure and install GEOS.

/usr/local/src user$ tar -xzf geos-1.0.0.tar.gz
/usr/local/src user$ cd geos-1.0.0
/usr/local/src/geos-1.0.0 user$ ./configure
/usr/local/src/geos-1.0.0 user$ make
/usr/local/src/geos-1.0.0 user$ sudo make install
[enter the su password]

Test your installation by running the command:

~ user$ geos-config --libs

If your installation was successful the output should be something like:

-L/usr/local/lib -lgeos

Install PostGIS 0.8.0

Download the source.
Read the documentation.
Put the tar file in the contrib directory of your configured PostgreSQL source tree.

/usr/local/src/postgresql-7.4/contrib user$ tar -xzf postgis-0.8.0.tar.gz
/usr/local/src/postgresql-7.4/contrib user$ cd postgis-0.8.0
/usr/local/src/postgresql-7.4/contrib/postgis-0.8.0 user$ make
/usr/local/src/postgresql-7.4/contrib/postgis-0.8.0 user$ sudo make install
[enter the su password]

Copy postgis.sql and spatial_ref_sys.sql from the postigs-0.8.0 directory to wherever you want, but be sure to remember the location, you’ll need those files later.

Login as postgres and start PostgreSQL:

/usr/local/src/postgresql-7.4 user$ su - postgres
[enter the postgres password]
~ postgres$ usr/local/bin/pg_ctl -D /usr/local/pgsql/data -l /usr/local/pgsql/data/postgres.log start

Create a test database and set up PostGIS support:

~ postgres$ /usr/local/bin/createdb test2
~ postgres$ /usr/local/bin/creatlang plpgsql test2
~ postgres$ /usr/local/bin/psql -d test2 -f postgis.sql
~ postgres$ /usr/local/bin/psql -d test2 -f spatial_ref_sys.sql

Now you should be able to use PostGIS.

你可能感兴趣的:(Installing PostGIS 0.8.0 on Mac OS 10.3.2)