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

问题描述:

我试图创建一个简单的c程序,它应该连接到我的postgres数据库,但我无法知道下面的编译错误...我使用的是Ubuntu(但也尝试在Fedora上编译 - 与为什么在尝试使用c连接到postgresql时遇到编译错误?

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) 

而且我发现了很多的HOWTO,但还是同样的结果:

我还检查在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 

我希望有人能帮助我在这里... THX BR , roegi

使用PGconn而不是PGConn

+0

THX很多!我读了100次左右的错误! – roegi 2011-05-27 10:45:05

如何:

#include <pgconn.h>