PostGIS 2.0 Build Using MinGW/MSYS/VisualC++

These directions are based on building a PostGIS 2.0 installation using a mixture of MinGW and Visual C++ (MSVC). Some of the libraries that PostGIS 2.0 depends on, such as GEOS and GDAL, are more frequently built and tested under MSVC than under MinGW.

Operating System

This build recipe has been put together and tested on Windows XP, with all current patches from Microsoft.


MinGW/MSYS have been recently revived using a lightweight package manager called '"mingw-get". Like apt-get and yum, mingw-get makes it very easy to pull down pieces of software and all the necessary dependencies in one step. First get the base installer for mingw-get.

Run the installer, and opt for support of C, C++ and MSYS. Once the install is finished, open up the "MinGW Shell" and run the following commands:

mingw-get install msys-bison msys-flex
mingw-get install msys-unzip msys-zip
mingw-get install msys-autoconf
mingw-get install msys-automake
mingw-get install msys-libtool
mingw-get install msys-wget
mingw-get install mingw32-gettext
mingw-get install mingw32-libiconv
mingw-get install mingw32-zlib mingw32-libz
mingw-get install mingw-utils

Then set up the build and target directories:

# target directory
mkdir /c/pgsql

# build directory
mkdir /c/build/
mkdir /c/build/sources
mkdir /c/build/binaries


In order to build the latest versions of PostGIS 2.0 you will need an SVN client, so download a command line SVN client. Pick only one of the following options: TortoiseSVN or Slik SVN.

Slik SVN

cd /c/build/binaries

Once you've downloaded, install with the default options.


Download an MSI installer from choosing either 32-bit or 64-bit OS versions for your system. Install with most default options BUT add "command line client tools", which is not enabled by default. After completing install, you will need to restart you computer as indicated.

Visual C++ Express

To build the MSVC libraries, you will need the free version of Visual C++, which microsoft makes available.

Download Visual C++ Express and install it.


CMake is a multi-platform build tool, used by GEOS to control compilation on non-UNIX platforms. Download CMake from:

Install, and opt to add to system path for all users when prompted.


GEOS is the geometry library underlying most of the PostGIS geometry functions.

cd /c/build/sources
#if this geos-3.3.3.tar.bz2 does not exist use
tar xvfj geos-3.3.3.tar.bz2
mkdir geos-3.3.3-build
cd geos-3.3.3
./configure --prefix=/c/pgsql

Edit the CMakeLists.txt file and add the following line to stop floating point precision issues (which will lead to regression failures in PostGIS later on if you don't make the change)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP /fp:strict /fp:except-")

ADD it right before this line


Open up the "Visual Studio 2008 Command Prompt", and run the build commands below.

cd \
cd build
cd sources
cd geos-3.3.3-build
cmake -G "NMake Makefiles" -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=C:\pgsql ..\geos-3.3.3
nmake install

Open up the "MinGW Shell" and clean out the static libraries and copy the dynamic libraries over to the lib dir:

cd /c/pgsql/bin
cp geos*dll ../lib
cd ../lib
rm geos*.lib

Now you have GEOS, but PostGIS is going to need a geos-config file to build, so…

cd /c/build/sources/geos-3.3.3
cp tools/geos-config /c/pgsql/bin
chmod 755 /c/pgsql/bin/geos-config


cd /c/build/sources
tar xvfj postgresql-9.1.3.tar.bz2
cd postgresql-9.1.3
./configure --prefix=/c/pgsql
make install


cd /c/build/sources
tar xvfj CUnit-2.1-2-src.tar.bz2
cd CUnit-2.1-2
./configure --prefix=/c/pgsql
make install


cd /c/build/sources
tar xvfz proj-4.6.1.tar.gz
cd proj-4.6.1/nad
unzip ../../

Edit the nmake.opt file and set the INSTDIR variable to c:\pgsql

Open up the "Visual Studio 2008 Command Prompt"

cd \
cd build\sources\proj-4.6.1
nmake -f
nmake -f install-all

Open up the "MinGW Shell" and clean out the static libraries and copy the dynamic libraries over to the lib dir:

cd /c/pgsql/bin
cp proj*dll ../lib
cd ../lib
rm proj*.lib

GTK+ Bundle

cd /c/build/binaries
unzip -d /c/pgsql

EnterpriseDB PostgreSQL

If you're planning on eventually copying the binaries into an EnterpriseDB build for distribution here's where to get the binaries:

cd /c/build/binaries
mkdir /c/pgsql-edb
unzip -d /c/pgsql-edb


You have to get libxml2 and its dependencies, iconv and zlib.

cd /c/build/binaries

cd libxml2-2.7.8.win32
cp -r bin/* /c/pgsql/bin
cp -r bin/* /c/pgsql/lib
cp -r include /c/pgsql/
cd ..

cd iconv-1.9.2.win32
cp -r bin/* /c/pgsql/bin
cp -r bin/* /c/pgsql/lib
cp -r include /c/pgsql/
cd ..

cd zlib-1.2.5.win32
cp -r bin/* /c/pgsql/bin
cp -r bin/* /c/pgsql/lib
cp -r include /c/pgsql/
cd ..

Now you have libxml2, but you don't have an xml2-config file. So…

cp /c/pgsql/bin/geos-config /c/pgsql/bin/xml2-config

Now edit /c/pgsql/bin/xml2-config so it returns the right answers!

  • Change the --libs option so that -lgeos becomes -lxml2 -lz -lpthread -liconv -lm
  • Change the --cflags option to return -I/c/pgsql/include


cd /c/build/sources
tar xvfz json-c-0.9.tar.gz
cd json-c-0.9
CFLAGS=-w ./configure --prefix=/c/pgsql --enable-shared --disable-static
make install
cd /c/pgsql/lib
a2dll libjson.a -o libjson.dll
cp libjson.dll ../bin
rm libjson.a

Once JSON-C is installed, make some alterations to its headers to prevent conflicts during PostGIS compile. Open up /c/pgsql/include/json/json_object.h remark out line 32 that reads typedef int boolean so it should now read / typedef int boolean; /


Getting a working GDAL is an involved process…

cd /c/build/sources
tar xvfz gdal-1.9.0.tar.gz
cd gdal-1.9.0
./configure --prefix=/c/pgsql
cd apps
make gdal-config
cd ..

In order get get all the symbols linking you need to edit nmake.opt appropriately. Find the following line in the file and disable STDCALL by following the directions (commenting out the line and adding the CPL_DISABLE_STDCALL flag to the OPTFLAGS later in the file.

# If you don't want some entry points to have STDCALL conventions, 
# comment out the following and add -DCPL_DISABLE_STDCALL in OPTFLAGS.
# This option has no effect on 64-bit windows.

While you're at it, also carry out the following edits:

GDAL_HOME = "C:\pgsql"

Set the version string to blank


Note on the above: Blanking out the version string is necessarily to line up the DLL name with the expectation of the PostGIS configure script that gdal will be named "gdal" and not "gdal19". This is fine for a one-time compile, but in the long run, to avoid DLL conflicts, we would be better off with a properly named GDAL and having the PostGIS configure process pick up the right name from the gdal-config script and apply it to all tests.

Open up the "Visual Studio 2008 Command Prompt"

cd \
cd build\sources\gdal-1.9.0
nmake -f MSVC_VER=1500
nmake -f MSVC_VER=1500 install

Copy the dynamic gdal-config script into place.

cp apps/gdal-config /c/pgsql/bin
chmod 755 /c/pgsql/bin/gdal-config

Copy the static libraries across

cp /c/pgsql/bin/gdal19.dll /c/pgdal/lib/gdal.dll

Ensure gdal-config returns the right answers!

Copy the header files over, since the install process seems to not move them.

cd /c/build/sources/gdal-1.9.0
cp gcore/*.h /c/pgsql/include
cp port/*.h /c/pgsql/include
cp ogr/*.h /c/pgsql/include
cp alg/*.h /c/pgsql/include
cp frmts/vrt/*.h /c/pgsql/include


Now we are ready to try and build PostGIS. Using the "MinGW Shell",

cd /c/build/sources
svn co postgis-svn
cd postgis-svn

Before building, edit one file to allow the regression tests to run, edit ./regress/ and set


Now you can configure and build,

export PATH=$PATH:/c/pgsql/bin
cd /c/build/sources/postgis-svn

CPPFLAGS="-I/c/pgsql/include" LDFLAGS="-L/c/pgsql/lib" ./configure \
  --with-xml2config=/c/pgsql/bin/xml2-config \
  --with-pgconfig=/c/pgsql/bin/pg_config \
  --with-geosconfig=/c/pgsql/bin/geos-config \
  --with-projdir=/c/pgsql \
  --with-gdalconfig=/c/pgsql/bin/gdal-config \
  --with-jsondir=/c/pgsql \
  --with-libintl-prefix=/c/pgsql \

#this part is a hack, but again didn't work without it #you can try without doing this, but if you get errors about # conflicting type def boolean during PostGIS compile, you need this. #In my case I got this:

c:/projects/json-c/rel-0.9/include/json/json_object.h:32: error: conflicting types for 'boolean'
C:/MinGW/bin/../lib/gcc/mingw32/3.4.5/../../../../include/rpcndr.h:52: error: previous declaration of 'boolean' was here
  • Open up /c/projects/json-c/rel-0.9/include/json/json_object.h
  • remark out line 32 that reads

typedef int boolean

  • so it should now read

/** typedef int boolean; **/

  • During the PostGIS configure process, you have to put this back the way it was otherwise configure complains json.h or something is not usable and refuses to configure with JSON-C support. Then you remark the line out again during compile. Crazy I know, but json-c won't compile without that line so can't take it out before json-c compile.

If you run into problems with your build, pipe the output into a file for further analysis. The GUI requires that pkg-config be on your PATH, check that it is there by running 'which pkg-config'.

make 2>&1 | tee /c/build.log
make check
make install
Last modified 11 years ago Last modified on Mar 4, 2012, 3:19:09 PM
Note: See TracWiki for help on using the wiki.