Changes between Initial Version and Version 1 of DevWikiWinMingW64_21


Ignore:
Timestamp:
Jul 31, 2012, 4:53:38 AM (12 years ago)
Author:
robe
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • DevWikiWinMingW64_21

    v1 v1  
     1== Compiling using MingGW-w64 for 64-bit ==
     2[wiki:UsersWikiWinCompile Back to Compiling in Windows]
     3
     4There are issues with GEOS compile above 4.5.4 or so, in 4.6.1+, the make check crashes and so does
     5PostGIS tests when compiled with GCC 4.6+.  That said you should pick a build lower than GCC 4.6. We like GCC 4.5.4
     6Issues are documented in http://trac.osgeo.org/geos/ticket/518 (also similar issue compiling Geos under windows 64-bit SDK http://trac.osgeo.org/geos/ticket/528 )
     7
     8== 1. Installing Minimalist GNU for Windows-w64 (MinGW-w64) ==
     9We will use MingGW-w64 toolchain instead of the standard MingW since it has support for both 32-bit and 64-bit compiling.
     10For this discussion we are using the binaries built for running on Windows. We haven't tried the builds designed for building windows binaries under Linux/Unix.
     11
     12Details of the prefixes of files can be found at [http://sourceforge.net/apps/trac/mingw-w64/wiki/download%20filename%20structure What to download]
     13
     14MingW-w64 site is [http://mingw-w64.sourceforge.net]
     15
     16 * If you are building for 64-bit Windows download the sezero personal build from [http://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win32/Personal%20Builds/sezero_4.5_20111101/] with name
     17starting with '''mingw-w64-bin_x86_64-mingw_20111101_sezero.zip'''
     18
     19 * If you are building for 32-bit Windows download one of the binary packages from [http://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win32/Personal%20Builds/sezero_4.5_20111101/] with name starting with
     20'''mingw-w32-bin_i686-mingw_20111101_sezero.zip'''
     21
     22 * Extract your respective zip into a folder called C:\ming64\mingw64 or c:\ming32\mingw32
     23 * Download the latest patch in same folder e.g. sezero_20111101-w32-update-rev.5151.zip for win32, sezero_20111101-w64-update-rev.5151.zip for win64 and extract into same respective folders.
     24
     25
     26
     27/** NOTE to self: This may not be necessary anymore **/
     28GEOS fails to link if it picks up 32-bit dlls so to overcome this, I copied over the dlls from windows/sytem32 and renamed them as
     29described in
     30#linking errors seems to be caused by as described here [http://www.gaia-gis.it/spatialite-3.0.0-BETA/mingw64_how_to.html#env]
     31mingw64 is picking up the 32-bit dlls from syswow64 instead of the 64-bit dlss from windows/system32
     32I only needed to copy ws2_32.dll for geos to compile without errors
     33Others may be needed not sure.
     34with windows explorer copy the files from windows/system32
     35
     36{{{
     37ws2_32.dll
     38}}}
     39
     40To your folder: C:\ming64\x86_64-w64-mingw32\lib
     41and then rename them adding a lib extensions so you have
     42{{{
     43libws2_32.dll
     44# these ones didn't seem necessary for PostGIS: libmsimg32.dll,libgdi32.dll, libcrypt32.dll and libwldap32.dll
     45}}}
     46
     47GEOS also gives missing vtable message during link.  I think this was caused by msys missing find.exe, so I copied the find.exe from regular msys packaged as instructed in the above link to bin of my msys.
     48
     49
     50== prefixed files ==
     51These sometimes exist only with the prefixes and cause issues during compilation so you'll need prefixless versions
     52
     53{{{
     54cp /mingw/bin/x86_64-w64-mingw32-cpp.exe /mingw/bin/cpp.exe
     55cp /mingw/bin/x86_64-w64-mingw32-strip.exe /mingw/bin/strip.exe
     56}}}
     57
     58== 2. Installing Msys ==
     59
     60MSys is 32-bit but you can use it with your 32-bit or 64-bit mingw-w64.  Instructions are here [http://sourceforge.net/apps/trac/mingw-w64/wiki/MSYS mingw-w64 with MSYS] and repeated
     61here for completeness
     62
     63 *  download [http://sourceforge.net/projects/mingw-w64/files/External%20binary%20packages%20%28Win64%20hosted%29/MSYS%20%2832-bit%29/ Msys] MSYS-20110309.zip (update there is now a newer MSYS -- MSYS-20110526.zip)
     64 * Extract into a folder called C:\Msys
     65 * launch msys.bat
     66 * type
     67
     68{{{
     69sh /postinstall/pi.sh
     70}}}
     71
     72When prompted type in
     73{{{C:/ming64/mingw64}}} or {{{C:/ming32/mingw32}}}  depending on which tool chain you chose
     74Once done, type logout and the console should exit.
     75
     76== 3a. Installing Autoconf, Automake and Libtool ==
     77Relaunch C:\mysy\msys.bat
     78
     79{{{
     80export PROJECTS=/c/ming64/projects
     81}}}
     82
     83
     84Verify which versions of these you have with
     85
     86autoconf --version
     87
     88etc.
     89
     90If they are not newer (or you get not found) than below then download and install.
     91Download the source code from the GNU site and save to c:\projects
     92
     93 * http://ftp.gnu.org/gnu/autoconf/autoconf-2.65.tar.gz
     94 * http://ftp.gnu.org/gnu/automake/automake-1.11.1.tar.gz
     95 * http://ftp.gnu.org/gnu/libtool/libtool-2.4.tar.gz
     96
     97
     98{{{
     99
     100cd ${PROJECTS}
     101tar -xvf autoconf-2.65.tar.gz
     102cd autoconf-2.65
     103./configure --host=x86_64-w64-mingw32 --prefix=/mingw  (if you are building for 32-bit then use --host=i686-w64-mingw32)
     104make && make install
     105autoconf --version
     106}}}
     107
     108repeat same exercise for automake
     109
     110For libtool
     111{{{
     112cd ${PROJECTS}
     113tar -xvf libtool-2.4.10.tar.gz
     114
     115cd libtool-2.4.10
     116./configure --host=x86_64-w64-mingw32 --disable-shared --prefix=/mingw
     117#if you are building on 32-bit then use --host=i686-w64-mingw32 for the host
     118#if you get a message that gcc is not usable, then you probably set your
     119# mingw setting wrong or did not install automake/autotools in /mingw
     120#try to fix by rerunning the sh /postinstall/pi.sh again
     121make clean && make && make install
     122libtool --version
     123
     124}}}
     125
     126== 3.b create project folders ==
     127
     128{{{
     129 export PROJECTS=/c/ming64/projects
     130 cd ${PROJECTS}
     131 mkdir pg
     132 mkdir postgresql
     133 mkdir geos
     134 mkdir proj
     135 mkdir docbook
     136 ls
     137
     138}}}
     139
     140== GDAL ==
     141{{{
     142export GDAL_VER=1.9.1
     143cd ${PROJECTS}/gdal
     144wget http://download.osgeo.org/gdal/gdal-${GDAL_VER}.tar.gz
     145tar xvfz gdal-1.9.1.tar.gz
     146cd gdal-${GDAL_VER}
     147./configure --host=x86_64-w64-mingw32 --build=x86_64-w64-mingw32 --with-threads=no --prefix=${PROJECTS}/gdal/rel-${GDAL_VER}w64
     148make && make install
     149cd ${PROJECTS}/gdal/rel-${GDAL_VER}w64/bin
     150strip *.dll
     151}}}
     152
     153== DOWNLOAD DOCBOOK ==
     154cd ${PROJECTS}/docbook
     155Download the latest Docbook from http://sourceforge.net/projects/docbook/files/docbook-xsl/
     156into that folder and untar.
     157
     158Extract somewhere. In this case I chose my projects folder.  You'll need to set this folder for the --with-xsldir
     159setting
     160
     161You should have a folder now docbook/docbook-xsl-1.76.1  or something similar
     162
     163
     164== 4. Compiling GEOS ==
     165
     166Download latest GEOS source from http://trac.osgeo.org/geos/ either the http://download.osgeo.org/geos/geos-3.3.3.tar.bz2
     167You can also use the trunk svn version https://svn.osgeo.org/geos/trunk. If you are using svn version, make sure to run:
     168
     169{{{
     170sh autogen.sh
     171}}}
     172
     173
     174this fails at linker phase with a whole bunch of errors if you compile without doing
     175#linking errors seems to be caused by as described here [http://www.gaia-gis.it/spatialite-3.0.0-BETA/mingw64_how_to.html#env]
     176mingw64 is picking up the 32-bit dlls from syswow64 instead of the 64-bit dlss from windows/system32
     177I may have over-copied, but to remedy before evening starting configure
     178with windows explorer copy the files from windows/system32
     179
     180{{{
     181ws2_32.dll, kernel32.dll, advapi32.dll, mscvrt.dll, user32.dll
     182}}}
     183
     184To your folder: C:\mingw\mingw64\x86_64-w64-mingw32\lib
     185and then rename them adding a lib extensions so you have
     186{{{
     187libws2_32.dll, libkernel32.dll, libadvapi32.dll, libmscvrt.dll, libuser32.dll
     188}}}
     189
     190# hack described in [http://www.gaia-gis.it/spatialite-3.0.0-BETA/mingw64_how_to.html#libgeos]
     191
     192{{{
     193simplify/.libs/libsimplify.a(TopologyPreservingSimplifier.o):TopologyPreservingS
     194implifier.cpp:(.rdata+0x1f0): undefined reference to `geos::geom::util::GeometryTransformer::transformGeometryCollection(geos::geom::GeometryCollection const*,
     195geos::geom::Geometry const*)'
     196
     197and bunch of other classes in util::GeometryTransformer..
     198the .la file gets created so seems to be at linker phase.
     199}}}
     200
     201-- follow instructions in [http://www.gaia-gis.it/spatialite-3.0.0-BETA/mingw64_how_to.html#libgeos]
     202{{{
     203export GEOS_VER=3.3.5
     204cd ${PROJECTS}/geos
     205tar xjf geos-${GEOS_VER}.tar.bz2
     206cd geos-${GEOS_VER}
     207./configure --host=x86_64-w64-mingw32 --prefix=${PROJECTS}/geos/rel-${GEOS_VER}w64 | tee /c/geos_configure_3.3.log
     208make
     209make install
     210}}}
     211To strip all the debug info weight from the libgeos DLL files, run
     212{{{
     213strip ${PROJECTS}/bin/geos/rel-${GEOS_VER}w64/*.dll
     214}}}
     215
     216==  Installing !LibIconv ==
     217
     218For iconv we are going to compile our own copy instead of installing from GNUWin.
     219
     220 * http://ftp.gnu.org/gnu/libiconv/libiconv-1.13.1.tar.gz
     221
     222Save the source in your C:\ming64\projects directory. Open up the MSYS terminal. Ignore the errors in the configure process.
     223{{{
     224cd ${PROJECTS}
     225tar xvfz libiconv-1.13.1.tar.gz
     226cd libiconv-1.13.1
     227./configure --host=x86_64-w64-mingw32 --build=x86_64-w64-mingw32 --target=x86_64-w64-mingw32 --prefix=${PROJECTS}/rel-libiconv-1.13.1w64
     228make
     229make install
     230}}}
     231Copy rel-.. contents int c:\mingw\mingw64 folder.  For some reason using libiconv-prefix did not work for configuring postgis.
     232Verify if the version of iconv you are running is the same as the one you just compiled (1.13):
     233{{{
     234# iconv --version
     235}}}
     236
     237== Compiling Proj ==
     238Download  Proj4 from the web site, and the datum shifts grid file.
     239
     240    *  http://download.osgeo.org/proj/proj-4.8.0.tar.gz
     241    *  http://download.osgeo.org/proj/proj-datumgrid-1.5.zip
     242
     243and copy to c:\ming64\projects\proj
     244The datum grid file must be unzipped into the "nad" subdirectory of the Proj4 source tree.
     245{{{
     246 #set this to whereever you plan to keep your source
     247 #I have one for 32-bit and one for 64-bit
     248 export PROJECTS=/c/ming64/projects   
     249 cd ${PROJECTS}/proj
     250 wget http://download.osgeo.org/proj/proj-4.8.0.tar.gz
     251 wget http://download.osgeo.org/proj/proj-datumgrid-1.5.zip
     252 tar xvfz proj-4.8.0.tar.gz
     253 cd proj-4.8.0
     254 cd nad
     255 unzip ../../proj-datumgrid-1.5.zip
     256 cd ..
     257 ./configure --prefix=${PROJECTS}/proj/rel-4.8.0w64 --host=x86_64-w64-mingw32 --enable-shared
     258 make clean
     259 make && make install
     260}}}
     261
     262== Compiling and Installing C-Unit ==
     263Download from http://sourceforge.net/projects/cunit/ into c:\projects
     264
     265{{{
     266cd ${PROJECTS}
     267wget http://iweb.dl.sourceforge.net/project/cunit/CUnit/2.1-2/CUnit-2.1-2-src.tar.bz2
     268tar -xvf CUnit-2.1-2-src.tar.bz2
     269cd CUnit-2.1-2
     270#if you are building for 64-bit then use x86_64-w64-mingw32 for the build,host,target
     271#32 bit uses i686-w64-mingw32 for build, host, target
     272./configure --host=x86_64-w64-mingw32 --prefix=/mingw
     273make && make install
     274}}}
     275
     276For some reason, PostGIS couldn't find my cunit install.  So I had to copy the files:
     277from C:\ming64\mingw64\include\CUnit to C:\ming64\mingw64\x86_64-w64-mingw32\include\CUnit
     278== 7. Compiling LibXML2 ==
     279
     280{{{
     281mkdir ${PROJECTS}/libxml
     282cd ${PROJECTS}/libxml
     283wget ftp://xmlsoft.org/libxml2/libxml2-2.7.8.tar.gz
     284}}}
     285
     286
     287{{{
     288 tar xvfz libxml2-2.7.8.tar.gz
     289cd libxml2-2.7.8
     290#if you are building for 64-bit then use x86_64-w64-mingw32 for the build,host,target
     291#32 bit uses i686-w64-mingw32 for build, host, target
     292 ./configure --prefix=/c/projects/libxml/rel-libxml2-2.7.8w64 --build=x86_64-w64-mingw32 --host=x86_64-w64-mingw32 --target=x86_64-w64-mingw32 --enable-shared --with-threads=no  CFLAGS=-O2
     293#Note to self: used to have CCFLAGS=LDFLAGS="-Wl,-static"  in here will see how it goes without
     294#If you have pthreads installed, libxml picks it up and royally screws up thus the need for --with-threads=no
     295 make
     296 make install
     297}}}
     298
     299You might get an error during the configure process
     300{{{
     301/bin/rm: cannot lstat `libtoolT': No such file or directory
     302}}}
     303
     304That error seems safe to ignore.
     305
     306== 8. Compiling PostgreSQL 9.1 ==
     307Download source from:
     308[http://ftp.postgresql.org/pub/source/v9.1.3/postgresql-9.1.3.tar.bz2]
     309
     310{{{
     311mkdir ${PROJECTS}/pgx64
     312cd postgresql
     313tar -xvjf postgresql-9.1.3.tar.bz2
     314cd postgresql-9.1.3
     315#if you are building for 64-bit then use x86_64-w64-mingw32 for the build,host,target
     316#32 bit uses i686-w64-mingw32 for build, host, target
     317#EnterpriseDb VC++ 64-bit builds are compiled with disable float8 by val.
     318#If we don't include this line, the modules compiled against mingw64 will be incompatible with edb builds
     319./configure --prefix=${PROJECTS}/pgx64/pg91 \
     320 --build=x86_64-w64-mingw32 \
     321 --host=x86_64-w64-mingw32 --target=x86_64-w64-mingw32 \
     322 --with-pgport=5441 --enable-cassert --enable-debug \
     323 --enable-integer-datetimes --disable-float8-byval --without-zlib
     324
     325 make
     326 make install
     327#initialize the database cluster
     328/c/projects/pgx64/pg91/bin/initdb -U postgres -D ${PROJECTS}/pgx64/pg91/data -A trust
     329}}}
     330
     331== Compiling JSON-C ==
     332This is needed if you want ST_GeomFromGeoJSON to be functional.
     333Download [http://oss.metaparadigm.com/json-c/json-c-0.9.tar.gz] and save to c:\ming64\projects\json-c
     334{{{
     335cd ${PROJECTS}/json-c
     336wget http://oss.metaparadigm.com/json-c/json-c-0.9.tar.gz
     337tar xvfz json-c-0.9.tar.gz
     338cd json-c-0.9
     339## had to compile with -w (disable warnings otherwise it gave errors)
     340## if using 32-bit (ming32), use i686-w64-mingw32 for host/build
     341./configure --build=x86_64-w64-mingw32 \
     342 --host=x86_64-w64-mingw32 --target=x86_64-w64-mingw32 \
     343 --prefix=/c/projects/json-c/rel-0.9w64 CFLAGS=-w
     344make clean
     345make
     346make install
     347}}}
     348== Copy over needed dlls to PostgreSQL folders ==
     349
     350{{{
     351export PATHOLD=$PATH
     352export PATH=$PATH:/c/projects/pgx64/pg91edb/bin:/mingw
     353export PGHOST=localhost
     354export PGPORT=5441
     355export PGUSER=postgres
     356cp /c/projects/geos/rel-3.3.3w64/bin/*.dll /c/projects/pgx64/pg91edb/bin
     357cp /c/projects/gdal/rel-1.9.0w64/bin/*.dll /c/projects/pgx64/pg91edb/bin
     358cp /c/projects/proj/rel-4.7.0w64/bin/*.dll  /c/projects/pgx64/pg91edb/bin
     359cp /c/mingw/mingw64/bin/libgcc_s_sjlj-1.dll /c/projects/pgx64/pg91edb/bin
     360cp /c/projects/geos/rel-3.3.3w64/bin/*.dll /c/projects/pgx64/pg91/bin
     361cp /c/projects/gdal/rel-1.9.0w64/bin/*.dll /c/projects/pgx64/pg91/bin
     362cp /c/projects/proj/rel-4.7.0w64/bin/*.dll  /c/projects/pgx64/pg91/bin
     363cp /c/mingw/mingw64/bin/libgcc_s_sjlj-1.dll /c/projects/pgx64/pg91/bin
     364}}}
     365
     366== Getting GTK ==
     367If you want to build the shp2pgsql-gui loader in 64-bit, you can use the pre-compiled gtk bundle
     368which already has the needed headers
     369
     370{{{
     371export PORJECTS=/c/ming64/projects/gtk
     372cd ${PROJECTS}
     373mkdir gtk
     374cd gtk
     375wget
     376http://ftp.gnome.org/pub/gnome/binaries/win64/gtk+/2.22/gtk+-bundle_2.22.1-20101229_win64.zip
     377unzip gtk+-bundle_2.22.1-20101229_win64.zip
     378}}}
     379
     380
     381
     382== Compiling PostGIS 2.0 ==
     383 * There is a problem at least for my Mingw64 that prevents functions like ST_AsText and ST_AsKML that makes it leave out digits randomly
     384 * This also causes issues for shp2pgsql.  The issue is the fact that the MingW64 chain uses
     385 * Microsoft's vsprintf version instead of the C99 one. This version when space is not enough returns an error code instead of length of output the write
     386 * To work around this issue, I put in this pretty ugly hack in the liblwgeom/string_buffer.c around line 210
     387change:
     388{{{
     389        if ( len < 0 )
     390                return len;
     391}}}
     392
     393to:
     394{{{
     395        if ( len < 0 )
     396                len = _vscprintf(fmt, ap2);
     397}}}
     398
     399Details of this issue are outlined in #1668
     400               
     401{{{
     402export PROJECTS=/c/ming64/projects
     403export PG_VER=91
     404export PGWINVER=${PG_VER}edb
     405export GEOS_VER=3.3.5
     406# had to override the paths since cunit was picking up 32-bit junk and crashing
     407export PATHOLD=".:/bin:/include:/mingw/bin:/mingw/include:/c/Windows/system32:/c/Windows:/c/ming64/mingw64/include"
     408export PATH="${PATHOLD}:${PROJECTS}/pgx64/pg${PG_VER}/bin:${PROJECTS}/pgx64/pg${PG_VER}/lib"
     409#needed to build comments and shp2pgsql-gui
     410export PATH="${PATH}:${PROJECTS}/xsltproc:${PROJECTS}/gtk/bin"
     411export POSTGIS_SRC=${PROJECTS}/postgis/postgis-${POSTGIS_MICRO_VER}
     412cd /c/ming64/projects
     413mkdir postgis
     414cd postgis
     415wget http://www.postgis.org/download/postgis-${POSTGIS_MICRO_VER}.tar.gz
     416tar xvf postgis-${POSTGIS_MICRO_VER}.tar.gz
     417cd ${POSTGIS_SRC}
     418
     419CPPFLAGS="-I${PROJECTS}/pgx64/pg${PG_VER}/include -I${PROJECTS}/gettextrel-gettext-0.18.1/include -I${PROJECTS}/rel-libiconv-1.13.1w64/include" \
     420LDFLAGS="-L${PROJECTS}/pgx64/pg${PG_VER}/lib -L${PROJECTS}/gdal/rel-${GDAL_VER}/lib -L${PROJECTS}/gettext/rel-gettext-0.18.1/lib -L${PROJECTS}/rel-libiconv-1.13.1w64/lib" ./configure \
     421 --host=x86_64-w64-mingw32  \
     422  --with-xml2config=${PROJECTS}/libxml/rel-libxml2-2.7.8w64/bin/xml2-config \
     423  --with-pgconfig=${PROJECTS}/pgx64/pg${PG_VER}/bin/pg_config \
     424  --with-geosconfig=${PROJECTS}/geos/rel-${GEOS_VER}/bin/geos-config \
     425  --with-projdir=${PROJECTS}/proj/rel-4.7.0w64 \
     426  --with-gdalconfig=${PROJECTS}/gdal/rel-${GDAL_VER}/bin/gdal-config \
     427  --with-jsondir=${PROJECTS}/json-c/rel-0.9w64 \
     428  --with-libiconv=${PROJECTS}/rel-libiconv-1.13.1w64 \
     429   --with-xsldir=${PROJECTS}/docbook/docbook-xsl-1.76.1 \
     430  --with-gui --with-gettext=no
     431}}}
     432
     433#this part is a hack, but again didn't work without it
     434#you can try without doing this, but if you get errors about
     435# conflicting type def boolean during PostGIS compile, you need this.
     436#In my case I got this:
     437{{{
     438In file included from c:/ming64/projects/json-c/rel-0.9w64/include/json/json_util.h:1
     439
     440                 from c:/projects/json-c/rel-0.9w64/include/json/json.h:23,
     441                 from lwgeom_in_geojson.c:31:
     442c:/ming64/projects/json-c/rel-0.9w64/include/json/json_object.h:32: error: conflictin
     443types for 'boolean'
     444c:\mingw\mingw64\bin\../lib/gcc/x86_64-w64-mingw32/4.4.7/../../../../x86_64-w6
     445mingw32/include/rpcndr.h:52: note: previous declaration of 'boolean' was here
     446make[1]: *** [lwgeom_in_geojson.o] Error 1
     447}}}
     448
     449 * Open up /c/projects/json-c/rel-0.9/include/json/json_object.h
     450 * remark out line 32 that reads
     451    {{{ typedef int boolean }}}
     452 * so it should now read
     453    {{{ /** typedef int boolean; **/ }}}
     454 * 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.
     455
     456If 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'.
     457{{{
     458make 2>&1 | tee /c/build.log
     459make check
     460make install
     461}}}