为什么在尝试使用 c 连接到 postgresql 时会出现编译错误?
我尝试创建一个简单的 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
,并在调用 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
我希望有人可以在这里帮助我...... 谢谢, 罗埃吉
I tried to create a simple c programm which should connect to my postgres db, but I am not able to get aware of the following compilation errors...
I am using Ubuntu (but also tried to compile on Fedora already - with the same errors...)
uname --all
Linux alp2nwmon001 2.6.35-25-server #44-Ubuntu SMP Fri Jan 21 19:09:14 UTC 2011 x86_64 GNU/Linux
I installed postgres inclusive libpq-dev libpq5 libs already and I have no clue why this simple code is not working...
#include "/usr/include/postgresql/libpq-fe.h"
int main () {
PGConn *test;
return 0;
}
I also tried lots of variations like: #include <libpq-fe.h>
, and specify the path to the .h file when calling gcc.
But always the same errors...
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)
Further I found a lot of howtos, but still the same result:
- http://www.mkyong.com/database/how-to-building-postgresql-libpq-programs/
- http://forum.ubuntu-fr.org/viewtopic.php?pid=3212499
I also checked the API description at the postgres webpage, still no luck.
In my opinion all files exist where the should exist...
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
And the libraries...
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
I hope somebody can help me here...
Thx br,
roegi
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用
PGconn
而不是PGConn
。Use
PGconn
instead ofPGConn
.