无法在 Visual Studio 2019 中 运行 libpq 示例

Can not run libpq examples in Visual Studio 2019

我是 C++ 新手。 我下载了 https://ftp.postgresql.org/pub/source/v13.1/postgresql-13.1.tar.gz from https://www.postgresql.org/ftp/source/ 并解压了它。

我在 VS Community 2019 中创建了一个新项目。将示例 postgresql-13.1\src\test\examples\testlibpq3.c 添加到项目中。

将我的 postgresql-13.1\src\includepostgresql-13.1\src\interfaces\libpq 目录添加到项目的 "Include Directories"

已将 Program Files\PostgreSQL\lib 添加到 "Library Directories"(此目录包含 libpq.lib)。

当我尝试编译时,出现 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 错误。

我在 postgresql-13.1 目录中查找 pg_config_ext.h。它不在那里。只有 postgresql-13.1\src\include\pg_config_ext.h.in.

请告诉我我错过了什么?让示例编译和 运行 的最简单方法是什么?提前致谢。

您需要配置、构建和安装 PostgreSQL,以便将所有头文件放在正确的位置。

安装 PostgreSQL 二进制文件会更简单,它们包含构建客户端代码所需的所有头文件。