2

I have built PostgreSQL source using MSVC2015 compiler for 64bit support and installed on Windows. Now, I want to build PostGIS also from source (I am referencing from this documentation). I am using MinGW. First, I had problems with a missing PGXS makefile which I have solved by installing the PostgreSQL server development package (from Debian). Now, the configure file is complaining about missing libpq:

checking for PQserverVersion in -lpq... no

configure:error: could not find libpq

Upon closer inspection at the config.log file, this stands out:

error C:/PostgreSQL/9.6/lib/libpq.dll: file not recognized: File format not recognized

I have found this which suggests either an incompatibility between compilers or trying to combine a 64bit version with a 32bit one. Well, I made sure to compile in 64bit throughout - maybe I can somehow verify this?

Otherwise, if it is a problem with compilers, the PostgreSQL compilation was only working with MSVC and I cannot use this for PostGIS to my knowledge.

I am trying to make a contribution to PostGIS so there is no point using the binary installation. I understand it is not ideal to use Windows, however I would very much like the solution to work on Windows at the end of the day.

2

I build the PostGIS packages for windows.

Here is my tip.

1) Compile PostgreSQL under mingw64 as well. It will save you a lot of grief. Stay away from compiling under VC++. The packages you create will work just fine under VC++ as well as mingw64.

2) Then build postgis against the mingw64 compiled PostgreSQL.

My scripts for building PostGIS dependencies, including PostgreSQL are here:

https://gist.github.com/robe2/5942642

You can also download my build chain (which is listed in the gist). I think I already have PostgreSQL built under mingw as part of my chain.

I'll update it in a bit to include PostGIS 2.4 stuff (the protobuf stuff coming) and also the newer dependencies I ship with PostGIS windows builds.

For running PostgreSQL, I use a launch script that has the paths:

@ECHO ON
REM The script sets environment variables helpful for PostgreSQL
SET OS_BUILD=64
SET GCC_TYPE=gcc48
SET MINGW=C:\ming%OS_BUILD%%GCC_TYPE%\mingw%OS_BUILD%
SET PROJECTS=C:\ming%OS_BUILD%%GCC_TYPE%\projects
SET GDAL_VER=2.1.1
SET GEOS_VER=3.6.1
SET PGDATA=%~dp0\data
SET PGDATABASE=postgres
SET PGUSER=postgres
SET PGPORT=5446
SET ICONV_VER=1.13.1
SET PROJ_VER=4.9.1
SET LIBXML_VER=2.7.8
SET CURL_VER=7.44.0
SET EXPAT_VER=2.1.0
SET FREEXL_VER=1.0.1
SET OPENSSL_VER=1.0.1p
SET V8_VER=3.14.5
SET PCRE_VER=8.33
SET PROTOBUF_VER=3.2.0
@SET SFCGAL_VER=1.3.0
@SET CGAL_VER=4.6.1
@SET SQLite_VER=3
@SET PROJSO=libproj-9.dll
@SET ORACLE_HOME=C:\app\Administrator\product\11.2.0\client_1
@SET TNS_ADMIN=C:\app\Administrator\product\11.2.0\client_1\network\admin


@SET GDAL_DATA=%PROJECTS%\gdal\rel-%GDAL_VER%w%OS_BUILD%%GCC_TYPE%\share\gdal
@SET PATH=%PROJECTS%\CGAL\rel-cgal-%CGAL_VER%w%OS_BUILD%%GCC_TYPE%\bin;%PROJECTS%\cgal\rel-sfcgal-%SFCGAL_VER%w%OS_BUILD%%GCC_TYPE%\bin;%MINGW%\bin;%~dp0bin;%PROJECTS%\gdal\rel-%GDAL_VER%w%OS_BUILD%%GCC_TYPE%\bin;%PROJECTS%\geos\rel-%GEOS_VER%w%OS_BUILD%%GCC_TYPE%\bin;%PROJECTS%\rel-libiconv-%ICONV_VER%w%OS_BUILD%%GCC_TYPE%\bin;%PROJECTS%\proj\rel-%PROJ_VER%w%OS_BUILD%%GCC_TYPE%\bin;%PROJECTS%\libxml\rel-libxml2-%LIBXML_VER%w%OS_BUILD%%GCC_TYPE%\bin;%PROJECTS%\curl\rel-curl-%CURL_VER%w%OS_BUILD%%GCC_TYPE%\bin;%PROJECTS%\expat\rel-expat-%EXPAT_VER%w%OS_BUILD%%GCC_TYPE%\bin;%PROJECTS%\freexl\rel-freexl-%FREEXL_VER%w%OS_BUILD%%GCC_TYPE%\bin;%PROJECTS%\v8\%V8_VER%;%PROJECTS%\ssl\rel-openssl-%OPENSSL_VER%w%OS_BUILD%%GCC_TYPE%\bin;%PROJECTS%\sqlite\rel-sqlite%SQLite_VER%w%OS_BUILD%%GCC_TYPE%\bin;%PROJECTS%\protobuf\rel-%PROTOBUF_VER%w%OS_BUILD%%GCC_TYPE%\bin;%~dp0\bin

echo %GDAL_DATA%
echo %PATH%

@REM SET POSTGIS_GDAL_ENABLED_DRIVERS=EHdr GTiff PNG JPEG GIF XYZ
REM SET POSTGIS_GDAL_ENABLED_DRIVERS=ENABLE_ALL

REM @SET GDAL_DATA="%PROJECTS%\gdal\rel-1.9.2\share\gdal"
@SET PGLOCALEDIR=%~dp0\share\locale
"%~dp0\bin\initdb" -E UTF8 -U postgres -A trust
"%~dp0\bin\pg_ctl" -D "%~dp0/data" -l logfile start
ECHO "Click enter to stop"
pause
"%~dp0\bin\pg_ctl" -D "%~dp0/data" stop -m fast

The Oracle stuff and V8 stuff you can ignore. I added PROTOBUF since that's a new dependency for PostGIS 2.4 coming up. https://trac.osgeo.org/postgis/ticket/3661

The launch script will work fine for both mingw64 PostgreSQL as well as PostgreSQL VC++ build. I usually test against PostgreSQL VC++ since that's what is used in StackBuilder.

  • Thanks! Your insights were very helpful and I made some big progress. Now I am trying to CREATE EXTENSION postgis and I get the message ERROR: could not load library "C:/../postgis-2.3.dll": The specified module could not be found. This module is there of course... So how can I debug such an issue? I am on latest PostgreSQL and PostGIS 2.3.2 – audlift-bit Feb 13 '17 at 1:13
  • The dependency files need to be in search path, for development I usually add this to postgres launch script. I'll update answer to include my launch script. Alternatively you can copy the files into bin folder, but I like to keep bin clean so I can swap out with newer PostgreSQL without any hassle. – LR1234567 Feb 13 '17 at 4:24
  • Forgot to mention, other reason I don't copy to bin is I like to swap out with newer versions of libraries before I deploy and it's cleaner if I don't have them in PostgreSQL bin folder. – LR1234567 Feb 13 '17 at 4:31
  • Thanks once again, and I now managed to make some working PostGIS build. One difficulty I have is that using the ming32gcc48 makepostgis script from bostonGIS, there are only about 51 regression test being run - is this correct? I thought there were more tests... perhaps I am running regression tests incorrectly? – audlift-bit Feb 18 '17 at 23:43
  • Audit which version of postgis are you building for? Tests have changed over the years and also depends what you've got enabled. E.g. if you are building without raster, topology that gets rid of about 100 tests right there. The sfcgal for main postgis, if you are not building with that, I think tests reduce by half since sfcgal basically repeats the regular postgis tests but with sfcgal enabled. I suspect that is why you only have 51. – LR1234567 Feb 22 '17 at 15:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.