我试图创建一个简单的 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,结果还是一样:
- http://www.mkyong.com/database/how-to-building-postgresql-libpq-programs/
- http://forum.ubuntu-fr.org/viewtopic.php?pid=3212499
我也检查了 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/