Search code examples
c++postgresqlvisual-studio-2019libpq

Can not run libpq examples in Visual Studio 2019


I am new to C++. I downloaded https://ftp.postgresql.org/pub/source/v13.1/postgresql-13.1.tar.gz from https://www.postgresql.org/ftp/source/ and unpacked it.

I created a new project in VS Community 2019. Added the example postgresql-13.1\src\test\examples\testlibpq3.c to the project.

Added my postgresql-13.1\src\include and postgresql-13.1\src\interfaces\libpq directories to "Include Directories" of the project.

Added Program Files\PostgreSQL\13\lib to "Library Directories" (this directory contains libpq.lib).

And when I try to compile, I get postgresql-13.1\src\include\postgres_ext.h(26,10): fatal error C1083: Cannot open include file: 'pg_config_ext.h': No such file or directory error.

I looked for the pg_config_ext.h in postgresql-13.1 directory. It's not there. Only postgresql-13.1\src\include\pg_config_ext.h.in.

Please tell me what am I missing? What's the easiest way to get the example to compile and run. Thanks in advance.


Solution

  • You need to configure, build and install PostgreSQL to have all the header files in the correct place.

    It would be simpler to install the PostgreSQL binaries, they include all the header files necessary to build client code.