Changes between Initial Version and Version 1 of DevWikiWinMingWSys_14_15


Ignore:
Timestamp:
Oct 4, 2010, 8:29:28 AM (14 years ago)
Author:
robe
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • DevWikiWinMingWSys_14_15

    v1 v1  
     1= Compiling PostGIS 1.4 and 1.5 under Windows using MinGW/Msys =
     2
     3A 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.
     4
     5== Install Directories ==
     6
     7We have used the following install directories:
     8
     9MinGW: c:\MinGW[[BR]]
     10Msys: c:\msys[[BR]]
     11sources c:\thesrc[[BR]]
     12installdirectory for postgresql: c:\postgres
     13
     14== Useful Utilities ==
     15
     16A good tool for extracting tar-files is 7-zip from http://www.7-zip.org
     17
     18== 1. Installing Minimalist GNU for Windows (MinGW) ==
     19
     20Download Automated MinGW Installer 5.1.4 version from [http://es.sourceforge.jp/projects/sfnet_gridlab-d/downloads/support/Version%202.0/MinGW-5.1.4.exe/ here] (Current version from http://sourceforge.net/project/showfiles.php?group_id=2435)
     21
     22 1. Run the setup file and choose everything (except possibly Ada)
     23 2. Accept the default Install location of C:\MinGW
     24 
     25== 2. Installing Minimal System (MSYS) ==
     26
     27MSYS provides you with a unix shell environment for compiling code under windows.
     28
     29Download MSYS version 1.0.11. http://sourceforge.net/projects/mingw/files/MSYS%20Base%20System/msys-1.0.11/MSYS-1.0.11.exe/download (this is listed in http://sourceforge.net/project/showfiles.php?group_id=2435)
     30
     31 1. Say y to post Installation
     32 2. When prompted do you have MinGW -> y
     33 3. When prompted for where it is type -> C:\MinGW
     34   
     35== 3. Installing Mys Development Toolkit ==
     36
     37Download the MysDTK1.0.1 from http://downloads.sourceforge.net/mingw/msysDTK-1.0.1.exe
     38
     39     1. Run the EXE install and accept all the defaults
     40 
     41== 4. Installing GNUWin Support Packages ==
     42
     43Download and install the following from http://gnuwin32.sourceforge.net/packages.html. Run each file and be sure to change the install directory to '''c:\MinGW'''
     44
     45 * Bison, http://kent.dl.sourceforge.net/sourceforge/gnuwin32/bison-2.1.exe
     46 * zlib, http://kent.dl.sourceforge.net/sourceforge/gnuwin32/zlib-1.2.3.exe
     47 * Flex, http://kent.dl.sourceforge.net/sourceforge/gnuwin32/flex-2.5.4a-1.exe
     48 * !GetText, http://kent.dl.sourceforge.net/sourceforge/gnuwin32/gettext-0.14.4.exe
     49   * Also get the !GetText dependencies file http://kent.dl.sourceforge.net/sourceforge/gnuwin32/gettext-0.14.4-dep.zip and unzip it into C:\MinGW
     50 * Unzip, http://kent.dl.sourceforge.net/sourceforge/gnuwin32/unzip-5.51-1.exe
     51
     52
     53
     54== 5. Update m4 ==
     55
     56 1. download from: http://prdownloads.sourceforge.net/mingw/m4-1.4.7-MSYS.tar.bz2?download
     57 2. untar and copy the m4.exe-file in the end of the path to C:\msys\1.0\bin
     58
     59== 6. Update environment variables ==
     60
     61The below is copied direct from http://www.mingw.org/wiki/HOWTO_Install_the_MinGW_GCC_Compiler_Suite#toc33
     62
     63  ''Environment Settings''
     64
     65  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.
     66
     67  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.[[BR]]
     68
     69   1. Right-click on "My Computer" and select "Properties".
     70   2. Click Advanced -> Environment Variables.
     71   3. In the box entitled "System Variables" scroll down to the line that says "PATH" and double-click the entry.
     72   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!
     73   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.
     74   6. press OK -> OK -> OK and you are done.
     75
     76Set the environment variable HOME to C:\msys\1.0\home. Create it if it doesn't already exist.
     77
     78== 7. Installing !LibIconv ==
     79
     80For iconv we are going to compile our own copy instead of installing from GNUWin.
     81
     82 * http://ftp.gnu.org/gnu/libiconv/libiconv-1.13.1.tar.gz
     83
     84Save the source in your C:\thesrc directory. Open up the MSYS terminal. Ignore the errors in the configure process.
     85{{{
     86# cd /c/thesrc
     87# tar xvfz libiconv-1.13.1.tar.gz
     88# cd libiconv-1.13.1
     89# ./configure --prefix=/c/mingw
     90# make
     91# make install
     92}}}
     93Verify if the version of iconv you are running is the same as the one you just compiled (1.13):
     94{{{
     95# iconv --version
     96}}}
     97
     98== 8. Installing Autoconf, Automake and Libtool ==
     99
     100Download the source code from the GNU site:
     101
     102 * http://ftp.gnu.org/gnu/autoconf/autoconf-2.65.tar.gz
     103 * http://ftp.gnu.org/gnu/automake/automake-1.11.tar.gz
     104 * http://ftp.gnu.org/gnu/libtool/libtool-2.2.10.tar.gz
     105
     106Save the packages in the c:\thesrc folder.
     107
     108Launch the MSYS terminal from Start->Programs->MinGW->msys or from the desktop MSYS icon.
     109{{{
     110# cd /c/thesrc
     111# ls
     112}}}
     113Now 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.
     114{{{
     115# tar xvfz autoconf-2.65.tar.gz
     116# cd autoconf-2.65
     117# ./configure --prefix=/c/mingw
     118# make
     119# make install
     120# autoconf --version
     121}}}
     122If 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.
     123{{{
     124which autoconf
     125}}}
     126Now configure, compile and install automake.
     127{{{
     128# tar xvfz automake-1.11.tar.gz
     129# cd automake-1.11
     130# ./configure --prefix=/c/mingw
     131# make
     132# make install
     133}}}
     134Now configure, compile and install libtool.
     135{{{
     136# tar xvfz libtool-2.2.10.tar.gz
     137# cd libtool-2.2.10
     138# ./configure --prefix=/c/mingw
     139# make
     140# make install
     141}}}
     142 
     143== 9. Compiling PostgreSQL ==
     144
     145Download latest [http://www.postgresql.org/ftp/source/ PostgreSQL source] and untar in C:\thesrc
     146{{{
     147# tar xvfz postgresql-8.4.3.tar.gz
     148# cd postgresql-8.4.3
     149# ./configure --prefix=/c/postgres
     150# make
     151# make install
     152}}}
     153If you want to be able to do a full make check on PostGIS, [UsersWikiWinCompileInitdb Initialize the postgresql database cluster] first.
     154   
     155Note that we now have changed the install-directory from /c/MingW to /c/postgres.
     156
     157=== PostgreSQL 8.3 ===
     158
     159If you are compiling PostgreSQL 8.3 and you get a compilation error like this:
     160{{{
     161e:/mingw/bin/../lib/gcc/mingw32/3.4.5/../../../../include/sspi.h:60: error: syntax error before SECURITY_STRING
     162In file included from e:/mingw/bin/../lib/gcc/mingw32/3.4.5/../../../../include/security.h:39,
     163from libpq-int.h:57,
     164from fe-auth.h:18,
     165from fe-auth.c:48:
     166e:/mingw/bin/../lib/gcc/mingw32/3.4.5/../../../../include/ntsecpkg.h:123: error: syntax error before SECURITY_STRING
     167}}}
     168The 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:
     169{{{
     170#ifdef ENABLE_SSPI
     171#define SECURITY_WIN32
     172#include <ntsecapi.h> <- Add this include line
     173#include <security.h>
     174#undef SECURITY_WIN32
     175}}}
     176You can read about this issue [http://pgolub.wordpress.com/2008/12/15/building-postgresql-client-library-using-mingw-under-winxp-sp3/ here] and
     177[http://postgresqlorg.blogspot.com/2008/09/hackers-83-4-vista-mingw-initdb.html here].
     178
     179=== PostgreSQL 8.4 ===
     180
     181The above problem has been fixed in PostgreSQL 8.4.1.
     182
     183== 10. Compiling GEOS ==
     184
     185Download latest GEOS source from http://trac.osgeo.org/geos/ either the http://download.osgeo.org/geos/geos-3.2.1.tar.bz2 or http://download.osgeo.org/geos/geos-svn.tar.bz2 .
     186{{{
     187# bzip2 -d -c geos-3.2.1.tar.bz2 | tar xvf -
     188# ./configure --prefix=/c/postgres
     189# make
     190# make install
     191}}}
     192To strip all the debug info weight from the libgeos DLL files, run
     193{{{
     194# strip /c/postgres/bin/libgeos-3-2-1.dll
     195}}}
     196
     197=== GEOS 3.2 ===
     198
     199If 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.
     200
     201I 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)
     202{{{
     203  //using ::swprintf; 
     204  //using ::vswprintf;
     205}}}
     206Refer to this [http://sourceforge.net/tracker/index.php?func=detail&aid=2373234&group_id=2435&atid=102435 MinGW bug ticket] and [http://lists.osgeo.org/pipermail/geos-devel/2009-June/004240.htm mailing list entry] for more details.
     207
     208If you are runnning gcc 4.4.0 and you get complaints about link g++ you probably need to do this too. Change
     209{{{
     210library_names='libstdc++.dll.a'
     211}}}
     212to
     213{{{
     214#library_names='libstdc++.dll.a'
     215library_names='libstdc++.a'
     216}}}
     217in file /c/mingw/lib/libstdc++.la, as alluded to [http://www.nabble.com/GCC-4.4.0-fails-with-GMP-td24191439.html here].
     218
     219== 11. Compiling Proj4 ==
     220
     221Download [http://trac.osgeo.org/proj/ Proj4] from the web site, and the datum shifts grid file.
     222
     223 * http://download.osgeo.org/proj/proj-4.6.1.tar.gz
     224 * http://download.osgeo.org/proj/proj-datumgrid-1.5.zip
     225
     226The datum grid file must be unzipped into the "nad" subdirectory of the Proj4 source tree.
     227
     228{{{
     229# tar xvfz proj-4.6.1.tar.gz
     230# cd proj-4.6.1
     231# cd nad
     232# unzip ../../proj-datumgrid-1.5.zip
     233# cd ..
     234# ./configure --prefix=/c/postgres --enable-shared --disable-static
     235# make
     236# make install
     237}}}
     238Make the libproj.dll and make it dynamically linked
     239{{{
     240# cd /c/postgres/lib
     241# 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
     242}}}
     243
     244Note: The [http://download.osgeo.org/proj/proj-4.7.0.tar.gz 4.7.0 version] can be used, but causes problems. More information [http://trac.osgeo.org/proj/ticket/56 here] and [http://trac.osgeo.org/proj/ticket/72 here].
     245
     246
     247== 12. Installing C-Unit ==
     248
     249C-Unit is a testing framework, and is needed by PostGIS 1.4 and above to run the "make check" testing step.
     250
     251 1. Download http://sourceforge.net/projects/cunit/files/CUnit/CUnit-2.1-0-winlib.zip
     252 2. Extract and copy contents to C:\MinGW 
     253
     254== 13. Compiling LibXML2 ==
     255
     256LibXML2 is only needed for PostGIS 1.5+.
     257
     258 1. mkdir /c/thesrc/libxml
     259 2. cd /c/thesrc/libxml
     260 3. ftp://xmlsoft.org/libxml2/libxml2-2.7.6.tar.gz
     261 4.  For windows it crashes currently unless you compile libxml statically which means
     262it gets embedded in the postgis-1.5.dll
     263{{{
     264# tar xvfz libxml2-2.7.6.tar.gz
     265# cd libxml2-2.7.6
     266# ./configure --prefix=/c/thesrc/libxml/libxml2-2.7.6release --disable-shared CCFLAGS=LDFLAGS="-Wl,-static" CFLAGS=-O2
     267# make
     268# make install
     269}}}
     270
     271== 14. Install GTK+ Bundle ==
     272
     273If you are compiling the shp2pgsql-gui program, you will need the GTK+ bundle.
     274
     275 * http://www.gtk.org/download-windows.html
     276 * http://ftp.gnome.org/pub/gnome/binaries/win32/gtk+/2.16/gtk+-bundle_2.16.6-20091013_win32.zip
     277
     278Unzip the bundle in c:\gtkbundle and then alter the system PATH so that c:\gtkbundle\bin is in the PATH.
     279
     280== 15. Compiling PostGIS ==
     281
     282=== PostGIS 1.4 ===
     283
     284Download http://postgis.refractions.net/download/postgis-1.4.1.tar.gz and put in C:/thesrc
     285{{{
     286# tar xvfz postgis-1.4.1.tar.gz
     287# cd postgis-1.4.1
     288# ./configure \
     289      --prefix=/c/postgres \
     290      --with-pgconfig=/c/postgres/bin/pg_config \
     291      --with-geosconfig=/c/postgres/bin/geos-config \
     292      --with-projdir=/c/postgres \
     293      --with-gui
     294# export PATH=/c/postgres/bin:$PATH
     295# make clean
     296# make
     297# make install
     298# make check
     299}}}
     300For running "make check" there is few extra steps that might be needed. See [UsersWikiMakeCheckConsiderations]
     301
     302If 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'.
     303{{{
     304# make 2>&1 | tee /c/build.log
     305}}}
     306
     307=== PostGIS 1.5 ===
     308{{{
     309# tar xvfz postgis-1.5.0.tar.gz
     310# cd postgis-1.5.0
     311
     312# ./configure \
     313     --prefix=/c/postgres \
     314     --with-xml2config=/c/thesrc/libxml/libxml2-2.7.6release/bin/xml2-config \
     315     --with-pgconfig=/c/postgres/bin/pg_config \
     316     --with-geosconfig=/c/postgres/bin/geos-config \
     317     --with-projdir=/c/postgres \
     318     --with-gui
     319
     320# export PATH=/c/postgres/bin:$PATH
     321# make clean
     322# make
     323# make install
     324# make check
     325}}}
     326
     327Might just be me, but to get PostGIS 1.5 to work under PostgreSQL 9.0 beta, had to do these steps right
     328after the ./configure  and then follow the rest of the steps above.  The PostgreSQL 9.0 mangled
     329the ${PERL} global having it point at a strange place. The below hack assumes you already have Perl in search
     330path and just replaces the $(PERL) placeholder with perl executable.
     331
     332{{{
     333sed 's,$(PERL),perl,g' <postgis/Makefile >postgis/Makefile2
     334mv postgis/Makefile2 postgis/Makefile
     335}}}
     336
     337=== Installing into PostgreSQL ===
     338
     339 1. Copy the following files into your Windows PostgreSQL lib folder
     340   * C:\postgres\lib\postgis-1.4.dll
     341 2. Copy the following files into your Windows PostgreSQL bin folder.
     342   * C:\postgres\bin\libgeos-3-2-0.dll
     343   * C:\postgres\bin\libgeos_c-1.dll
     344   * C:\postgres\bin\libproj.dll,
     345   * C:\postgres\bin\libiconv-2.dll (from C:\MinGW\bin)
     346   * C:\postgres\bin\libpq.dll (from C:\postgres\lib)
     347   * C:\postgres\bin\shp2pgsql.exe
     348   * C:\postgres\bin\pgsql2shp.exe
     349 3. If you compiled with-gui - you need to also copy the following files to PostgreSQL bin folder
     350   * shp2pgsql-gui.exe
     351   * And put gtk_bundle/bin in your path (if you need to distribute -- copy along the
     352 gtk_bundle/bin  and gtk_bundle/etc - hopefully this big footprint need will change for future versions)
     353 4. Copy the proj datum shift files to the PostgreSQL share/contrib/postgis/proj
     354 5. Open PGAdmin and make a new database without any template
     355 6. Open a new query-window to your new database
     356 7. Add PL/PgSQL procedural language to the new database: createlang plpgsql
     357 8. Run postgis.sql and spatial_ref_sys.sql from C:\postgres\share\contrib\
     358
     359Hopefully you now have a database running your recently compiled postgis.