Tag: msys

Building PostgreSQL 8.0.x using MinGW under Win… Magician wanted

Compiling the fresh PostgreSQL releases is not a problem under Windows using MinGW as you probably know.

One of my clients asked me to build pg_dump\pg_restore if it’s possible of course. Yes, I know that 8.0.x and 8.1.x branches are not supported anymore. At least officially. I was just curious.

Well, I spent a day making compiler happy. I built the client library libpq.dll, but dump and restore utilities are beyond my power.

The last words were:

pg_backup_archiver.o:pg_backup_archiver.c:(.text+0x43a): undefined reference to `__’
collect2: ld returned 1 exit status
make: *** [pg_dump] Error 1

Possibly my changes caused this. Since I’m not so familiar with GCC universe I’m still confused about it. Gurus’ advices appreciated.

And the last but not least. Is there any chance that MinGW compatibility patches for 8.0.x and 8.1.x branches will be committed officially?


PS Kids don’t do drugs!

Client libraries for PostgreSQL 8.4.0 update

Since PostgreSQL 8.4.0 has been released, MicroOLAP updated deployment libraries (libpq.dll and dependencies) on the company site.

So, those who need only client libraries for applications deployment can obtain them from PostgresDAC Download page.

There are two archives:

  • Deployment libraries shipped with PostgreSQL 8.4.0 installation
  • Deployment libraries built with MinGW environment

The first one doesn’t need an explanation. Details on the second could be found in my previous post.


MinGW & BCC patches applied!

Thanks to the PostgreSQL community, part of which I definitely am :), Tom Lane applied patches against 8.4 branch that fix problems with MinGW and BCC described in my previous posts:

So, my first patches (approved and edited by Tom I suppose) are applied! Kudos!

Archive entries:

Building PostgreSQL client library using MinGW under WinXP SP3


Deploying Windows applications which work with PostgreSQL you often need to provide some client libraries, such as libpq.dll, with it. This particular library can be easily found in the PostgreSQL installation folder. As we all know modern versions of PostgreSQL are built with Microsoft Visual Studio 2005, which in turn makes us depend on MSVC run-time library. For example, libpq.dll library which shipped with PostgreSQL 8.3.5 version depends on:

  • comerr32.dll
  • gssapi32.dll
  • k5sprt32.dll
  • krb5_32.dll
  • libeay32.dll
  • libiconv2.dll
  • libintl3.dll
  • msvcr80.dll
  • ssleay32.dll

Here we can face very annoying things. What if user hasn’t the latest MSVC RTL? Of course there is a workaround – he can install Microsoft Visual C++ 2005 Redistributable Package (vcredist_x86.exe). But what if your tool is only 300Kb? Why make it 2.6Mb heavier?

In this article we’ll try to get rid of all these dependencies by building client libraries with MinGW.

Installing MinGW

Go to Mingw.org. If you first time here I suggest you to spend some time studying this site. At least you should find out differences between MinGW and MSYS.

Then at the Downloads Section get Automated MinGW Installer. I used MinGW 5.1.4 as it was the latest release at the moment.

Here are the screenshots of the installation process where you can see what I had chosen:

Download and Install option

Current package

Minimal type

I have MinGW installed into E:\MinGW\ and hereafter I will use this path.

Installing MSYS

Now it’s time for MSYS. Here you can find the detailed installation instructions. In my environment MSYS was installed into E:\MSYS\1.0\ path.

Downloading PostgreSQL sources

Version 8.3.5 of PostgreSQL was the latest official release at the moment of writing this article. The latest version could be found using File Browser. After downloading the archive, I have extracted its contents into E:\postgresql-8.3.5\ folder.

Let’s configure it

Run MSYS (a cyan “M” on your Desktop). Enter command to change the current directory to E:\postgresql-8.3.5:

$ cd /e/postgresql-8.3.5/

The next step is to configure the source tree for our system using configure script.


$ ./configure

If everything worked fine then the last lines of the output should look like this:

configure: error: zlib library not found
If you have zlib already installed, see config.log for details on the
failure. It is possible the compiler isn't looking in the proper directory.
Use --without-zlib to disable zlib support.

ZLib library is used for pg_dump and pg_restore utilities. Since I don’t need them right now (we need only libpq.dll) we should run modified command:

$ ./configure --without-zlib

We’ve configured the sources and they are ready to be built with make command. If you do not need SSL support then you can skip the next section and go streight to “Let’s build it” one.

Let’s configure it with SSL support

If you need SSL support (and you probably do) you should let configure know about it. To do this we need pass additional parameter --with-openssl:

$ ./configure --without-zlib --with-openssl

But we’ve got an error:

checking for CRYPTO_new_ex_data in -leay32... no
configure: error: library 'eay32' is required for OpenSSL

We need to install OpenSSL. The latest version can be found at http://www.openssl.org/ (0.9.8i at the moment). Download Windows pre-compiled binaries. Choose Win32 OpenSSL v0.9.8i (not Light version).

Install OpenSSL wherever you want (E:\OpenSSL in my case). Then go to lib\MinGW subfolder (E:\OpenSSL\lib\MinGW in my case) and copy all files into MinGW lib folder (E:\MinGW\lib in my case).

Let’s try again:

$ ./configure --without-zlib --with-openssl

Oh, it’s better now. configure found eay32 library. But now we have problem with ssleay32 library.

checking for CRYPTO_new_ex_data in -leay32... yes
checking for SSL_library_init in -lssleay32... no
configure: error: library 'ssleay32' is required for OpenSSL

The thing is PostgreSQL configure expects ‘ssleay32’ library will be called libssleay32.a, but we just have ssleay32.a. Well, let’s make configure happy – just rename ssleay32.a to libssleay32.a.

Finaly run:

$ ./configure --without-zlib --with-openssl

Let’s build it

If you want to build the whole server, then you probably need something like this:

$ cd /e/postgresql-8.3.5/src/
$ make all

Since we need only libpq.dll (at least I need only this for PostgresDAC) we should execute:

$ cd /e/postgresql-8.3.5/src/interfaces/libpq/
$ make

Oops, we got an error:

In file included from e:/mingw/bin/../lib/gcc/mingw32/3.4.5/../../../../include/security.h:38,
from libpq-int.h:57,
from fe-auth.h:18,
from fe-auth.c:48:
e:/mingw/bin/../lib/gcc/mingw32/3.4.5/../../../../include/sspi.h:60: error: syntax error before "SECURITY_STRING"
In file included from e:/mingw/bin/../lib/gcc/mingw32/3.4.5/../../../../include/security.h:39,
from libpq-int.h:57,
from fe-auth.h:18,
from fe-auth.c:48:
e:/mingw/bin/../lib/gcc/mingw32/3.4.5/../../../../include/ntsecpkg.h:123: error: syntax error before "SECURITY_STRING"

This issue was discussed in the Hackers PostgreSQL mailing list and discussion could be found in the archive.

The solution is to add an additional header file to

#define SECURITY_WIN32
#include <ntsecapi.h> <——- Add this include
#include <security.h>

Just interesting, will this patch be present in 8.4.x branch of PostgreSQL sources?

Now execute:

$ cd /e/postgresql-8.3.5/src/interfaces/libpq/
$ make

That’s all.

Gimme the binaries

Those who have no time neither desire playing with MinGW can get “Deployment libraries built with MinGW environment” from PostgresDAC Download page.


Special thanks to Anthony Caduto and Michael Smirnov for help.