Saturday, 25 August 2018

Building libpq on MSYS2 MinGW 64 bit for libpqxx

For Windows, although there is a PostgreSQL installer provided, the libpq in the installation directory cannot be used to link libpqxx on MSYS2. This post shows how to build libpq from source on MSYS2.

If libpqxx was linked against the libpq provided by the Windows installer, while the dll can be built successfully, a segmentation fault will occur every time a value is extracted from PGresult. This is because the installer version of libpq itself is linked against MSVC libraries (try select version(); in psql), whereas while building libpqxx, the gcc/mingw libraries are used.

The easy solution here is to build libpqon MSYS2 as well.

1. Download the sources from https://www.postgresql.org/ftp/source/v10.4/
2. Extract the archive and cd to the directory.
3. Run ./configure
4. Run make -C src/common
5. Run make -C src/interfaces/libpq

More details here.

After completing the steps, there should be a libpq.dll in src/interfaces/libpq. Copy this DLL to the PostgreSQL installation directory (yes, just run the installer beforehand, it will set up the directories and all that). Remember to rename the original to something else like libpq_original.dll instead of replacing it!

Now you can resume the steps in this post to build libpqxx.

No comments:

Post a Comment