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?

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

4 Comments

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?
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.
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.
This other question helped me get the rest of the setup figured out. 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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.