Changes between Version 132 and Version 133 of UsersWikiWinCompile


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

Legend:

Unmodified
Added
Removed
Modified
  • UsersWikiWinCompile

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