Building the MySQL and PostgreSQL libraries on Windows

MySQL

MySQL does not support gcc on Windows, only MSVC. Moved to a separate page.

PostgreSQL

Both the C and C++ interfaces build fine “out of the box” (except for the LDFLAGS issue mentioned below) when building shared libraries.

There is a problem when building static libraries, though. The C interface uses the Win32 SSPI authentication interface (secur32.dll). This library is not linked in by default when linking statically, and the Makefiles don't know that. Furthermore, any configure script that uses AC_CHECK_LIB or similar instead of pg_config to look for libpq will also need to link with secur32.dll. There are two solutions: either fix the Makefile and all downstream consumers, or disable SSPI.

Keeping SSPI means a little more work right now (to build libpq and libpqxx) but potentially less pain down the line (as long as downstream consumers use pg_config and / or pkg-config so you don't have to specify -lsecur32 manually).

''libpq'' (C interface)

First, get the latest source (currently 8.3.9 for the 8.3 branch) from http://www.postgresql.org/ftp/source/v8.3.9/ and extract it in a convenient place.

There is a bug in src/template/win32: it sets LDFLAGS unconditionally. Change this line:

LDFLAGS="-Wl,--allow-multiple-definition"

to this:

LDFLAGS="${LDFLAGS} -Wl,--allow-multiple-definition"

Next, SSPI (see above). To disable SSPI, open src/include/port/win32.h and comment out the lines near the top that define ENABLE_SSPI:

// #ifndef __BORLANDC__
// #define ENABLE_SSPI 1
// #endif

If you want to keep SSPI, open src/Makefile.global.in, search for -lws2_32, and add -lsecur32 at the end of that line so it looks like this:

ifeq ($(PORTNAME),win32)
LIBS += -lws2_32 -lshfolder -lsecur32
endif

Take care to edit src/Makefile.global.in and not src/Makefile.global, as the latter will be automatically regenerated from the former.

You will also need to fix configure scripts etc. for everything that uses libpq and add -lsecur32 to LDFLAGS or LIBS in the appropriate places.

Then configure:

$ LDFLAGS=-L/c/met.no/lib CPPFLAGS=-I/c/met.no/include ./configure --prefix=/c/met.no --disable-shared

We don't want to install the entire package (server and all); we'll just install the library and headers and the pg_config tool which is used by other packages (such as libpqxx) that link against libpq.

$ make -C src/port all
$ make -C src/backend utils/fmgroids.h
$ make -C src/backend ../../src/include/utils/fmgroids.h
$ make -C src/include all install
$ make -C src/interfaces/libpq all install
$ make -C src/bin/pg_config all install

''libpqxx'' (C++ interface)

First, get the latest source (currently 3.0.2) from http://pqxx.org/development/libpqxx/wiki/DownloadPage and extract it in a convenient place.

Then configure:

$ LIBS=-lsecur32 LDFLAGS=-L/c/met.no/lib CPPFLAGS=-I/c/met.no/include PG_CONFIG=/c/met.no/bin/pg_config.exe ./configure --prefix=/c/met.no --disable-shared

If you decided to drop SSPI, you can use a slightly shorter configure command line:

$ LDFLAGS=-L/c/met.no/lib CPPFLAGS=-I/c/met.no/include PG_CONFIG=/c/met.no/bin/pg_config.exe ./configure --prefix=/c/met.no --disable-shared

Finally, build and install:

$ make all install