I\'m trying to create a .dll with Visual Studios 2013. The project includes libpq functionality.
Per other stackoverflow posts, and other sources I\'ve found on the
I've successfully compiled the sample program by setting these project properties:
<pgsql install path>\include
and \lib
to VC++ Directories->Include and ->Library, correspondinglylibpq.lib
to Linker->Input->Additional dependenciesThis is the standard way to reference 3rd-party libs. It's just that they recommend using environment variables for their "base dirs" to avoid patching the project when it's under a VCS.
PATH=%PATH%;<pgsql install path>\bin
in Debugging->Environment since this dir isn't in PATH
on my system.It's not sufficient add the postgres lib directory to the project, you must also add
reference to libpq.lib
. Just add this line to one of your source .cpp
files:
#pragma comment(lib, "libpq.lib")
As noted by Marco A. the library must match a program bitness (32 or 64 bit): if you build 32-bit DLL (referred as Win32
) you must use 32 bit library; if 64-bit (x64
) - 64-bit library.
I have also faced same issue. Then I realized that I was building my application as a 32bit. I changed the target of my application to x64 and it compiled successfully