2

我试图创建一个简单的 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 的 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

我希望有人可以在这里帮助我...谢谢 br,roegi

4

1 回答 1

2

使用PGconn而不是PGConn.

于 2011-05-27T10:42:01.457 回答