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.
C:/PostgreSQL/9.6/lib/libpq.dll
even exist?