0

I'm trying to go through an example using C and PostgreSQL, but I'm unable to find the libpq-fe.h when I try to compile through Visual Studio Community 2015 on Windows. I've looked at this answer related to adding aditional dependencies, but the compiler keeps giving me the error:

C1083: Cannot open include file: 'libpq-fe.h': No such file or directory

In the Project Properties > Configuration Properties I've added the location for the libpq-fe.h header:

C/C++ > General > Additional Include Directories: C:\Program Files\PostgreSQL\9.5\include\libpq

As well as the library location:

Linker > General > Additional Library Directories: C:\Program Files\PostgreSQL\9.5\lib
Linker > Input > Additional Dependencies: libpq.lib

I haven't even started adding the PostgreSQL related code yet, here's the start of my main application, the error comes from line 3:

#include<stdio.h>
#include<stdlib.h>
#include<libpq-fe.h>

int main(void) {

Is there a step I'm missing or am I using the wrong property settings for VS2015?

Community
  • 1
  • 1
Shaun
  • 2,012
  • 20
  • 44

1 Answers1

2

I assume you installed postgresql using the enterpriseDB installer.

The include path should be C:\Program Files\PostgreSQL\9.5\include without libpq. Also make sure you set the settings for the same combination of Configuration and Platform as you are building.

Eelke
  • 20,897
  • 4
  • 50
  • 76
  • Thank you, this does get rid of the include file error. And I did use the enterpriseDB installer. But now when I do a test with `int lib_ver = PQlibVersion();`, I get a new error: `LNK2019: unresolved external symbol _PQlibVersion referenced in function _main`. Do I have to add files individually to the `Linker > Input > Additional Dependencies` list? – Shaun Jan 28 '16 at 20:43
  • I'm pretty sure the linker settings in your question are correct (I'm not at home to verify my own project at the moment). Did you install a 32 or 64 bits postgres and did you build for the same? Thought I'm not sure it matters for linking against libpq.lib but I know it does for the libpq.dll at runtime. – Eelke Jan 29 '16 at 10:10
  • I installed 64 bit postgres (postgresql-9.5.0-1-windows-x64) and I switched the settings, **Active solution platform** and **Platform** in the Configuration Manager to x64. – Shaun Jan 29 '16 at 14:44
  • [This other question helped me get the rest of the setup figured out.](http://stackoverflow.com/questions/34579664/linking-libpqxx-from-visual-studio-2015-on-windows-10?rq=1) I had to move some .dlls (which were in `C:\Program Files\PostgreSQL\9.5\bin`) into the project directory. This seems like it might not be the ideal solution, but trying to like to that **bin** directory didn't seem to help. – Shaun Jan 29 '16 at 20:59