wiki:UsersWikiWinCompile

Version 89 (modified by pramsey, 15 years ago) ( diff )

--

Compiling PostGIS 1.4 and 1.5 under Windows using MinGW/Msys

A step by step guide to compiling PostGIS in windows XP SP3. This guide assumes that you already have a PostgreSQL installation on your computer. You will have to compile PostgreSQL here too, but that is just for the process of compiling PostGIS.

Install Directories

We have used the following install directories:

MinGW: c:\MinGW
Msys: c:\msys
sources c:\thesrc
installdirectory for postgresql: c:\postgresql

Useful Utilities

A good tool for extracting tar-files is 7-zip from http://www.7-zip.org

1. Installing Minimalist GNU for Windows (MinGW)

Download Automated MinGW Installer (Current - MinGW-5.1.4) from http://sourceforge.net/project/showfiles.php?group_id=2435 (http://sourceforge.net/projects/mingw/files/Automated%20MinGW%20Installer/MinGW-5.1.4.exe/download)

  1. Run the setup file and choose everything (except possibly Ada)
  2. Accept the default Install location of C:\MinGW

2. Installing Minimal System (MSYS)

MSYS provides you with a unix shell environment for compiling code under windows.

Download MSYS version 1.0.11. http://sourceforge.net/projects/mingw/files/MSYS%20Base%20System/MSYS-1.0.11-rc-1.exe/download (this is listed in http://sourceforge.net/project/showfiles.php?group_id=2435)

  1. Say y to post Installation
  2. When prompted do you have MinGW -> y
  3. When prompted for where it is type -> C:\MinGW

3. Installing Msy Development Toolkit

Download the MysDTK1.0.1 from http://downloads.sourceforge.net/mingw/msysDTK-1.0.1.exe

  1. Run the EXE install and accept all the defaults

4. Installing GNUWin Support Packages

Download and install the following from gnuwin32.sourceforge.net/packages.html

  1. Bison, http://kent.dl.sourceforge.net/sourceforge/gnuwin32/bison-2.1.exe
  2. zlib, http://kent.dl.sourceforge.net/sourceforge/gnuwin32/zlib-1.2.3.exe
  3. Flex, http://kent.dl.sourceforge.net/sourceforge/gnuwin32/flex-2.5.4a-1.exe
  4. GetText, http://kent.dl.sourceforge.net/sourceforge/gnuwin32/gettext-0.14.4.exe
  5. Unzip, http://kent.dl.sourceforge.net/sourceforge/gnuwin32/unzip-5.51-1.exe

Run each file and be sure to change the install directory to c:\MinGW

5. Update m4

  1. download from: http://downloads.sourceforge.net/mingw/m4-1.4.7-MSYS.tar.bz2
  2. untar and copy the m4.exe-file in the end of the path to C:\msys\1.0\bin

6. Update environment variables

The below is copied direct from http://www.mingw.org/wiki/HOWTO_Install_the_MinGW_GCC_Compiler_Suite#toc33

Environment Settings

When you install command line tools, such as MinGW, or !GnuWin32 tools, you have to tell the command line interpreter where to find them; this is usually accomplished by adding the appropriate directory names to the PATH variable in your environment. Typically, it is your responsibility to do this; please do not expect the installer, (if you used one), to do it for you.

Warning: Adding entries to the PATH is normally benign. However, if you delete, you may mess up your PATH string, and you could seriously compromise the functioning of your computer. Please be careful.

  1. Right-click on "My Computer" and select "Properties".
  2. Click Advanced -> Environment Variables.
  3. In the box entitled "System Variables" scroll down to the line that says "PATH" and double-click the entry.
  4. You will be presented with a dialog box with two text boxes, the bottom text box allows you to edit the PATH variable. It is very important that you do not delete the existing values in the PATH string, this will cause all sorts of problems for you!
  5. Scroll to the end of the string and at the end add ";<installation-directory>\bin". Here <installation-directory> is the full absolute path name of the installation directory; if you accepted the defaults when installing tar and gzip, then for these, it will (probably) be C:\Program Files\!GnuWin32, while for MinGW it will be C:\MinGW\bin, (if you kept to the recommended default installation directory). Don't forget the semicolon; this separates the entries in the PATH.
  6. press OK -> OK -> OK and you are done.

Set the environment variable HOME to C:\msys\1.0\home

7. Installing LibIconv

For iconv we are going to compile our own copy instead of installing from GNUWin.

Save the source in your C:\thesrc directory. Open up the MSYS terminal.

# cd /c/thesrc
# tar xvfz libiconv-1.13.1.tar.gz
# cd libiconv-1.13.1
# ./configure --prefix=/c/mingw
# make
# make install

Verify you are running the latest version of iconv

# iconv --version

8. Installing Autoconf, Automake and Libtool

Download the sourcecode of:

  1. autoconf from ftp.gnu.org/gnu/autoconf
  2. automake from ftp.gnu.org/gnu/automake
  3. libtool from ftp.gnu.org/gnu/libtool

The latest releases 2009-11-11 are:

  • autoconf 2.65 (1.4MB)
  • automake 1.11.1 (1.2MB)
  • libtool 2.2.4 (1.8MB)

Make a folder c:\thesrc and untar the source-files there.

Launch MSys from Start->Programs->MinGW->msys or from the desktop MSYS icon.

You now get a terminal-window that understands a bunch of unix/linux-commands (at least enough for compiling)

# cd /c/thesrc
# ls

Now you will get the folders you have copied to the directory listed. The names of the folders will be different than in this example if you have newer releases of the tools. Configure, compile and install autoconf.

# cd autoconf-2.65
# ./configure --prefix=/c/mingw 
# make 
# make install
# autoconf --version

If it says you are running lower than 2.63, most likely you have another one installed in addition. Running the below will tell you which one it is picking up. {{ which autoconf }}} Now configure, compile and install automake.

# cd automake-1.11
# ./configure --prefix=/c/mingw
# make
# make install

Now configure, compile and install automake.

# cd libtool-2.2.4
# ./configure --prefix=/c/mingw
# make
# make install

9. Compiling PostgreSQL

Download latest PostgreSQL source and untar in C:\thesrc

# tar xvfz postgresql-8.4.1.tar.gz
# cd postgresql-8.4.1
# ./configure --prefix=/c/postgres
# make
# make install

If you want to be able to do a full make check on PostGIS, Initialize the postgresql database cluster first. Note that we now have changed the install-directory from /c/MingW to /c/postgres.

PostgreSQL 8.3

If you are compiling PostgreSQL 8.3 and you get a compilation error like this:

e:/mingw/bin/../lib/gcc/mingw32/3.4.5/../../../../include/sspi.h:60: error: syntax error before SECURITY_STRING
In file included from e:/mingw/bin/../lib/gcc/mingw32/3.4.5/../../../../include/security.h:39,
from libpq-int.h:57,
from fe-auth.h:18,
from fe-auth.c:48: 
e:/mingw/bin/../lib/gcc/mingw32/3.4.5/../../../../include/ntsecpkg.h:123: error: syntax error before SECURITY_STRING

The solution is to edit two of the PostgreSQL source files, src/include/libpq/libpq-be.h and src/interfaces/libpq/libpq-int.h, and add a new line in them in the ENABLE_SSPI block:

#ifdef ENABLE_SSPI
#define SECURITY_WIN32
#include <ntsecapi.h> <- Add this include line
#include <security.h>
#undef SECURITY_WIN32

You can read about this issue here and here.

PostgreSQL 8.4

The above problem has been fixed in PostgreSQL 8.4.

10. Compiling GEOS

Download latest GEOS source from http://trac.osgeo.org/geos/ either the http://download.osgeo.org/geos/geos-3.1.1.tar.bz2 or http://download.osgeo.org/geos/geos-svn.tar.bz2 .

# bzip2 -d -c geos-svn.tar.bz2 | tar xvf -
# ./configure --prefix=/c/postgres
# make
# make install

To strip all the debug info weight from the libgeos DLL files, run

# strip /c/postgres/bin/libgeos-3-2-0.dll

GEOS 3.2

If you are compiling the latest GEOS 3.2 (the SVN version), you may get an error because of a bug in MinGW. GEOS 3.2 is needed to take advantage of the new ST_Buffer enhancements in PostGIS 1.5+ and also some fixes for topology exceptions in intersects and intersection.

I had to comment out the lines as seen below, lines 159 and 166 in C:\MinGW\include\c++\3.4.5\cwchar (the same issue still exists under gcc 4.4.0)

  //using ::swprintf;  
  //using ::vswprintf;

Refer to this MinGW bug ticket and mailing list entry for more details.

If you are runnning gcc 4.4.0 and you get complaints about link g++ you probably need to do this too. Change

library_names='libstdc++.dll.a'

to

#library_names='libstdc++.dll.a' 
library_names='libstdc++.a'

As alluded to here.

11. Compiling Proj4

Download the latest Proj4 from the web site, and the datum shifts grid file.

The datum grid file must be unzipped into the "nad" subdirectory of the Proj4 source tree.

# tar xvfz proj-4.6.1.tar.gz
# cd proj-4.6.1
# cd nad
# unzip ../../proj-datumgrid-1.5.zip
# cd ..
# ./configure --prefix=/c/postgres --enable-shared --disable-static --without-mutex
# make
# make install

Make the libproj.dll and make it dynamically linked

# cd /c/postgres/lib
# gcc -shared -o libproj.dll -Wl,--out-implib=libproj.dll.a -Wl,--export-all-symbols -Wl,--enable-auto-import -Wl,--whole-archive libproj.a -Wl,--no-whole-archive /c/mingw/lib/libmingw32.a 

12. Installing C-Unit

C-Unit is a testing framework, and is needed by PostGIS 1.4 and above to run the "make check" testing step.

  1. Download http://sourceforge.net/projects/cunit/files/CUnit/CUnit-2.1-0-winlib.zip
  2. Extract and copy contents to C:\MinGW

13. Compiling libxml2

This is only needed for PostGIS 1.5+. Libxml2 is used to support the ST_GeomFromGML function. Download ftp://xmlsoft.org/libxml2/libxml2-sources-2.7.6.tar.gz

# tar xvfz libxml2-sources-2.7.6.tar.gz
# ./configure
# make
# make install

14. Compiling PostGIS

PostGIS 1.4

Download http://postgis.refractions.net/download/postgis-1.4.1.tar.gz and put in C:/thesrc

# tar xvfz postgis-1.4.1.tar.gz
# cd postgis-1.4.1
# ./configure \
      --prefix=/c/postgresql \
      --with-pgconfig=/c/postgresql/bin/pg_config \
      --with-geosconfig=/c/postgresql/bin/geos-config \
      --with-projdir=/c/postgresql
# export PATH=/c/postgres/bin:$PATH
# make clean
# make
# make install
# make check

If you run into problems with your build, pipe the output into a file for further analysis.

# make 2>&1 | tee /c/build.log

PostGIS 1.5

More to come here.

Installing into PostgreSQL

  1. Copy the following files into your Windows PostgreSQL lib folder
    • C:\postgresql\lib\postgis-1.4.dll
  2. Copy the following files into your Windows PostgreSQL bin folder.
    • C:\postgresql\bin\libgeos-3-1-1.dll
    • C:\postgresql\bin\libgeos_c-1.dll
    • C:\postgresql\bin\libproj.dll,
    • C:\postgresql\bin\libiconv-2.dll
    • C:\postgresql\bin\shp2pgsql.exe
    • C:\postgresql\bin\pgsql2shp.exe
  3. Copy the proj datum shift files to the PostgreSQL share/contrib/postgis/proj
  4. Open PGAdmin and make a new database without any template
  5. Open a new query-window to your new database
  6. Run postgis.sql and spatial_ref_sys.sql from C:\postgresql\share\contrib\

Hopefully you now have a database running your recently compiled postgis.

Note: See TracWiki for help on using the wiki.