wiki:DevWikiWinMingWSys_20_MSVC

Version 12 (modified by robe, 13 years ago) ( diff )

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

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.

http://sourceforge.net/projects/mingw/files/Installer/mingw-get-inst/mingw-get-inst-20111118/mingw-get-inst-20111118.exe

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

SVN

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
wget http://www.sliksvn.com/pub/Slik-Subversion-1.7.2-win32.msi

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

TortoiseSVN

Download an MSI installer from http://tortoisesvn.net/downloads.html 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.

http://www.microsoft.com/visualstudio/en-us/products/2008-editions/express

Download Visual C++ Express and install it.

CMake

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

http://www.cmake.org/cmake/resources/software.html

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

GEOS

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

cd /c/build/sources
wget http://download.osgeo.org/geos/geos-3.3.3.tar.bz2 
#if this geos-3.3.3.tar.bz2 does not exist use http://geos.osgeo.org/snapshots/geos-20120228.tar.bz2
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

add_definitions(-D_SCL_SECURE_NO_WARNINGS)

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
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

PostgreSQL

cd /c/build/sources
wget http://ftp.postgresql.org/pub/source/v9.1.3/postgresql-9.1.3.tar.bz2
tar xvfj postgresql-9.1.3.tar.bz2
cd postgresql-9.1.3
./configure --prefix=/c/pgsql
make
make install

CUnit

cd /c/build/sources
wget http://downloads.sourceforge.net/project/cunit/CUnit/2.1-2/CUnit-2.1-2-src.tar.bz2
tar xvfj CUnit-2.1-2-src.tar.bz2
cd CUnit-2.1-2
./configure --prefix=/c/pgsql
make
make install

Proj

cd /c/build/sources
wget http://download.osgeo.org/proj/proj-4.6.1.tar.gz
wget http://download.osgeo.org/proj/proj-datumgrid-1.5.zip
tar xvfz proj-4.6.1.tar.gz
cd proj-4.6.1/nad
unzip ../../proj-datumgrid-1.5.zip

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 makefile.vc
nmake -f makefile.vc 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
wget http://ftp.gnome.org/pub/gnome/binaries/win32/gtk+/2.24/gtk+-bundle_2.24.10-20120208_win32.zip
unzip gtk+-bundle_2.24.10-20120208_win32.zip -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
wget http://get.enterprisedb.com/postgresql/postgresql-9.1.3-1-windows-binaries.zip
mkdir /c/pgsql-edb
unzip postgresql-9.1.3-1-windows-binaries.zip -d /c/pgsql-edb

LibXML2

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

cd /c/build/binaries
wget ftp://ftp.zlatkovic.com/libxml/libxml2-2.7.8.win32.zip
wget ftp://ftp.zlatkovic.com/libxml/iconv-1.9.2.win32.zip
wget ftp://ftp.zlatkovic.com/libxml/zlib-1.2.5.win32.zip

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

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

unzip zlib-1.2.5.win32.zip
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

JSON-C

cd /c/build/sources
wget http://oss.metaparadigm.com/json-c/json-c-0.9.tar.gz
tar xvfz json-c-0.9.tar.gz
cd json-c-0.9
CFLAGS=-w ./configure --prefix=/c/pgsql --enable-shared --disable-static
make
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; /

GDAL

Getting a working GDAL is an involved process…

cd /c/build/sources
wget http://download.osgeo.org/gdal/gdal-1.9.0.tar.gz
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.
#STDCALL=YES

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

GDAL_HOME = "C:\pgsql"

Set the version string to blank

VERSION = 

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 makefile.vc MSVC_VER=1500
nmake -f makefile.vc 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

PostGIS

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

cd /c/build/sources
svn co http://svn.osgeo.org/postgis/trunk postgis-svn
cd postgis-svn
./autogen.sh

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

REGRESS_INSTALLDIR=C:/build/sources/postgis-svn/regress/00-regress-install

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 \
  --with-gui

#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
Note: See TracWiki for help on using the wiki.