postgresql - 为什么在尝试使用 c 连接到 postgresql 时出现编译错误?

标签 postgresql gcc libpq

我试图创建一个简单的 c 程序,它应该连接到我的 postgres 数据库,但我无法意识到以下编译错误... 我正在使用 Ubuntu(但也已尝试在 Fedora 上编译 - 出现相同的错误...)

uname --all
Linux alp2nwmon001 2.6.35-25-server #44-Ubuntu SMP Fri Jan 21 19:09:14 UTC 2011 x86_64 GNU/Linux

我已经安装了 postgres inclusive libpq-dev libpq5 库,我不知道为什么这个简单的代码不起作用......

#include "/usr/include/postgresql/libpq-fe.h"

int main () {
        PGConn *test;
        return 0;
}

我还尝试了很多变体,例如:#include <libpq-fe.h> , 并在调用 gcc 时指定 .h 文件的路径。 但总是同样的错误...

gcc -c -I/usr/include/postgresql/ -L/usr/lib/ -lpq pqtest.c -o postgres
 pqtest.c: In function main:
 pqtest.c:4: error: PGConn undeclared (first use in this function)
 pqtest.c:4: error: (Each undeclared identifier is reported only once
 pqtest.c:4: error: for each function it appears in.)
 pqtest.c:4: error: test undeclared (first use in this function)

进一步找了很多howtos,结果还是一样:

我也检查了 postgres 网页上的 API 描述,仍然没有运气。

在我看来,所有文件都存在于应该存在的地方......

ls -lah /usr/include/postgresql/libpq-fe.h 
-rw-r--r-- 1 root root 20K 2011-04-20 16:36 /usr/include/postgresql/libpq-fe.h

还有图书馆...

ls /usr/lib/ | grep pq
libpq.a
libpq.so
libpq.so.5
libpq.so.5.2
libpqxx-2.6.9.so
libpqxx.la
libpqxx.so

我希望有人能在这里帮助我... 谢谢, 罗吉

最佳答案

使用 PGconn 而不是 PGConn

关于postgresql - 为什么在尝试使用 c 连接到 postgresql 时出现编译错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6151050/

相关文章:

sql - Postgres : Why did adding index slow down regexp queries?

java - 如何在ebean中使用多个数据库

postgresql - 在 docker 中使用 pg_dump 出现“没有现有的本地集群适合”错误

c - C中的可变长度数组,它们是如何编译的

c++ set 输出的元素比它包含的元素多得多

go - 我可以在生产中使用 master libpq 吗

ruby-on-rails - 在 postgres heroku rails 3 应用程序上获取类名?

java - 无法打开共享对象文件: No such file or directory error while run time

postgresql - PQcmdTuples 中的 "cmd"代表什么?

postgresql - PQsetSingleRowMode 低性能