0

I am trying to build an application in Visual Studio 2013, linking with the libpq.lib library downloaded with the binary installer for PostgreSQL version 9.4 for Windows. I get this error:

LNK2038: mismatch detected for '_MSC_VER': value '1800' doesn't match value '1600' in ...

My assumption is that the downloaded library has been built with an earlier version of the MSVC compiler (Visual Studio 2010?).

I would like to know which MSVC compiler was used to build the various versions of libpq, from version 9.4, 9.5, .... 10.0.

My compile error indicates that the modern MSVC compilers / linker will check for consistency (value of _MSC_VER). Will that prevent linking with libpq.lib in VS2015 and VS2017? (Provided libpq.lib was built with VS2013).

Arild
  • 1
  • 1

1 Answers1

1

I assume that you are talking about the PostgreSQL binaries for Windows provided by EnterpriseDB.

All versions from 9.4 to v10 were built with Visual Studio 2013, and I have successfully used the Express Edition to build server extensions for Windows.

Laurenz Albe
  • 209,280
  • 17
  • 206
  • 263
  • Dowloaded from www.postgresql.com/download/... I am not aware if this is from EnterpriseDB or not. – Arild Nov 05 '17 at 14:09
  • Well, the download page points to the EnterpriseDB and the OpenSCG installers. I have no experience with the latter. Both of these are not from the PostgreSQL development group, which does not provide Windows builds. – Laurenz Albe Nov 05 '17 at 14:13
  • Thank you. My project is also considering migrating to Visual Studio 2015. Does that mean we will have problems linking with libpq.lib? And what about VS 2017? – Arild Nov 05 '17 at 14:17
  • I assume that there might be trouble if your program and libpq load different versions of the MSVC runtime environment. You might consider linking with [`/MT`](https://msdn.microsoft.com/en-us/library/2kzt1wy3.aspx) so that the C library gets statically linked into your program and there are no conflicts. It still might be a problem if you e.g. `free()` memory with one C library that has been `malloc()`ed with the other, so try to avoid things like that. You might want to read [this](http://siomsystems.com/mixing-visual-studio-versions/) interesting article. – Laurenz Albe Nov 05 '17 at 14:34
  • One final question: My compile error indicates that the modern MSVC compilers / linker will check for consistency (value of _MSC_VER). Will that prevent linking with libpq.lib in 2015 and 2017? (Provided libpq was built with VS2013). – Arild Nov 05 '17 at 15:06
  • MSVC shouldn't care about version mismatches anyway, it's generally happy to link libraries from other versions or other compilers. I routinely use much newer versions of VS to build with PostgreSQL binaries. So this is an odd issue. – Craig Ringer Nov 06 '17 at 01:40
  • @LaurenzAlbe libpq is pretty careful to avoid those issues, using static buffers and where that's not practical, exposing `PQfreemem` for freeing memory allocated by the library, or freeing it via other cleanup functions like `PQclear`. It avoids passing `FILE*` handles, and it's generally pretty cross-runtime safe. – Craig Ringer Nov 06 '17 at 01:41