wiki:UsersWikiWinCompile

Version 73 (modified by robe, 15 years ago) ( diff )

Compiling PostGIS under Windows using MinGW/Msys

A step by step guide how I managed to compile 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.

I have used this install directories:

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

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 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. MSYS Core 1.0.11 (note you do not need this if you installed MSYS-1.0.11.exe)

  1. Download MSYS Core 1.0.11 from http://downloads.sourceforge.net/mingw/msysCORE-1.0.11-2007.01.19-1.tar.bz2
  2. untar them and copy all content to c:\msys\1.0 and and click ok to overwrite existing files and folders.

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

(Make sure to Change install directory to c:\mingw)

  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

Note for iconv we are going to compile our own instead of install from gnuwin since gnuwin changed some constants

  1. LibIconv
    1. download source from http://ftp.gnu.org/gnu/libiconv (we are going to use libiconv-1.13.1.tar.gz)
    2. gzip -d -c libiconv-1.13.1.tar.gz | tar xvf -
    3. cd libiconv-1.13.1
    4. ./configure —prefix=/c/mingw
    5. make && make install

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

7. Update environment variable

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


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

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-04-11 is:

  • autoconf 2.63 (1.4MB)
  • automake 1.10.2 (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

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

  1. cd /c/thesrc
  2. 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.
move into one of the folders:

  1. cd autoconf-2.63

ok, now we are in the directory with the autoconf source-code
print:
ls
if you just see a new folder called autoconf-2.63 you have to go into that one to:
cd autoconf-2.63
when you se a lot of folders like bin and lib and a lot of files, then you are right
now we shall configure and make this tool
print:

  1. configure —prefix=/c/mingw && make && make install

now a lot of text shall appear in the window and after a while you will hopefully get no error-messages but jut get back to your prompt.

To verify you are not running autoconf-2.63 do the following:

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 go to the other source-code directories and do the same

  1. cd .. (backing to the directory c:\thesrc)
  2. cd automake-1.10.2
  3. configure —prefix=/c/mingw && make && make install
  1. cd .. (backing to the directory c:\thesrc)
  2. cd libtool-2.2.4
  3. configure —prefix=/c/mingw && make && make install

9. Compiling PostgreSQL
Download latest PostgreSQL source from http://www.postgresql.org/ftp/source/ and untar in C:\thesrc
move to folder

  1. cd /c/thesrc/postgresql-8.3.7 (the version of today)
  2. configure —prefix=/c/postgres && make && make install
  3. If you want to be able to do a full make check on PostGIS, Initialize the postgresql database cluster

note that we now have changed the install-directory from mingw to postgres

if you get an error something like:
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 source-files.
In both files:
postgresql-8.3.7/src/include/libpq/libpq-be.h
and
postgresql-8.3.7/src/interfaces/libpq/libpq-int.h:

add a new include-file:
#ifdef ENABLE_SSPI
#define SECURITY_WIN32
#include <ntsecapi.h> ← Add this include
#include <security.h>
#undef SECURITY_WIN32

you can read about this here:
http://pgolub.wordpress.com/2008/12/15/building-postgresql-client-library-using-mingw-under-winxp-sp3/
and
http://postgresqlorg.blogspot.com/2008/09/hackers-83-4-vista-mingw-initdb.html

10. Compiling GEOS
Download latest GEOS-source from trac.osgeo.org/geos/ ( http://download.osgeo.org/geos/geos-3.1.1.tar.bz2 ) and copy into C:\thesrc

Extract with: cd /thesrc

bzip2 -d -c geos-3.1.1.tar.bz2 | tar -xvf -

Do the same as with postgresql, extract to c:\thesrc
in msys terminal move to the GEOS source-code directory

  1. configure —prefix=/c/postgres && make && make install
  2. To strip all the debug info weight from the libgeos-3-1-1.dll run

strip /c/postgres/bin/libgeos-3-1-1.dll

NOTE: If you are compiling the latest GEOS (geos/trunk, you may get an error because of a bug in MingW).

I had to comment out like below — change lines (159, 166) to below (in C:\MinGW\include\c++\3.4.5\cwchar (same issue exists under gcc 4.4.0)

using ::swprintf;

using ::vswprintf;

refer to http://sourceforge.net/tracker/index.php?func=detail&aid=2373234&group_id=2435&atid=102435 and http://lists.osgeo.org/pipermail/geos-devel/2009-June/004240.html for details

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

and changing library_names='libstdc++.dll.a'

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

library_names='libstdc++.a'

As alluded to here http://www.nabble.com/GCC-4.4.0-fails-with-GMP-td24191439.html

11. Compiling Proj
Download latest Proj from trac.osgeo.org/proj/ (http://download.osgeo.org/proj/proj-4.6.1.zip )
in msys terminal move to the Proj source-code directory

  1. ./configure —prefix=/c/postgres —enable-shared —disable-static
  2. make && make install

—Make the libproj.dll and make it dynamically linked

  1. cd /c/postgres/lib
  2. 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 — needed for PostGIS 1.4 and above make check

  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 PostGIS SVN 1.4 (without shp2pgql-gui) (if you want to install with the GUI you need GTK Install GTK and PostGIS 1.4 with GUI)

  1. Download postgis.refractions.net/download/postgis-1.4.0.tar.gz and put in C:/thesrc
  2. cd /c/thesrc
  3. gzip -d -c postgis-1.4.0.tar.gz | tar xvf -
  4. cd postgis-1.4.0
  5. configure —prefix=/c/postgresql —with-pgconfig=/c/postgresql/bin/pg_config —with-geosconfig=/c/postgresql/bin/geos-config —with-projdir=/c/postgresql
  6. export PATH"/c/postgres/bin:$PATH"
  7. make clean && make
  8. make install
  9. make check Make Check gotchas

14. To use your new postgis

  1. copy postgis-1.4.dll from C:\postgresql\lib to your windows PostgreSQL lib folder
  2. copy C:\postgresql\bin\libgeos-3-1-1.dll,libgeos_c-1.dll, libproj.dll, libiconv-2.dll (depending on which version it could be libiconv-2.dll or libiconv2.dll), shp2pgsql.exe, pgsql2shp.exe to your PostgreSQL bin folder
  3. copy the proj datum shift files to 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.