【问题标题】:How to fix 'postgres.h' file not found problem?如何修复“postgres.h”文件未找到问题?
【发布时间】:2019-11-05 13:19:40
【问题描述】:

我正在尝试用 C(使用 xcode)为 PostgreSQL 编写一个基本类型,并且我已经安装了 PostgreSQL 11,但似乎 postgres.h 不能简单地包含在文件中(“'postgres.h' 文件不是找到”)。

谁能告诉我如何解决这个问题?我可以在任意目录下写代码,还是必须在PostgreSQL目录下写代码?

或者问题应该是:如何安装像postgres.h这样的头文件?

【问题讨论】:

  • 不是 Xcode 用户,但通常你必须告诉编译器在哪里寻找第三方头文件(然后是链接器在哪里寻找库本身,这可能是你的下一个问题)。 stackoverflow.com/questions/14134064/…
  • 如果安装了 postgres 二进制文件,也会安装 pg_config(在同一个 bin/ 目录中)。运行pg_config 将显示编译器和加载器标志。 (如果有)
  • 第一个问题是:你是怎么安装PostgreSQL的?如果来自包,则头文件通常位于您必须安装的不同“开发”包中。

标签: c postgresql postgresql-11


【解决方案1】:

用这个命令安装 postgresql-server-dev 包:

sudo apt install postgresql-server-dev-XX

将 [XX] 替换为您已安装的 postgresql:9.5、10、11、12 版本

【讨论】:

  • 推荐你实际运行sudo apt-cache search postgresql-server-dev。在 Kali linux 上,这些版本不存在。我个人需要sudo apt install postgresql-server-dev-all
  • 或者按照这篇文章中的说明安装您想要的任何版本:stackoverflow.com/questions/48868156/…
【解决方案2】:

这里有几种方法:

  • 自己搜索文件,使用类似的命令

    find / -name "postgres.h" -print
    

    这会告诉你(在我的 Mac 上)文件在:

    /usr/local/Cellar/postgresql/11.2_1/include/server/postgres.h
    

    并将-I /usr/local/Cellar/postgresql/11.2_1/include/server 选项添加到编译器。检查您的 postgresql 版本是否有可能使用不同的版本。

  • 可能还有另一个用于数据库开发的软件包。搜索名为postgresql-dev 或类似名称的包,然后安装它。搜索包后:

     brew search postgres 
    

     brew search psql
    

    在我的系统上没有出现任何匹配的内容。

编辑

我已经在 FreeBSD 系统中检查了该文件,它出现在

/usr/local/include/postgresql/server/postgres.h

所以可能你必须改用#include <server/postgres.h>,并使用适当的-I 标志(如上所述)

【讨论】:

  • 我使用了命令 'find / -name "postgres.h" -print' 并且有两行有用的输出:/usr/local/pgsql/include/server/postgres.h /usr /local/Cellar/postgresql/11.2/include/server/postgres.h 然后我使用 gcc -I /usr/local/Cellar/postgresql/11.2/include/server/,这是输出... clang:错误:没有输入文件...
  • 那你必须学习。如果您根本没有发布任何代码,我怎么能猜出您遇到的确切问题?从代码中出现编译问题......你甚至没有显示文件postgres.h#included的源代码行@d
猜你喜欢
  • 2020-11-27
  • 2019-09-04
  • 2018-06-28
  • 1970-01-01
  • 2021-03-13
  • 2018-09-22
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多