Debian 中的 libpq 库出现问题
我正在 Debian 中安装 postgresql 8.4,将程序 testlibpq.c 从 http: //www.postgresql.org/docs/9.0/interactive/libpq-example.html 到包含文件 libpq-fe.h 的目录,但编译后 gcc 写给我
testlibpq.c:(.text+0x4a): undefined reference to `PQconnectdb'
testlibpq.c:(.text+0x5a): undefined reference to `PQstatus'
testlibpq.c:(.text+0x6f): undefined reference to `PQerrorMessage'
testlibpq.c:(.text+0xa9): undefined reference to `PQexec'
testlibpq.c:(.text+0xb9): undefined reference to `PQresultStatus'
testlibpq.c:(.text+0xcf): undefined reference to `PQerrorMessage'
testlibpq.c:(.text+0xf5): undefined reference to `PQclear'
testlibpq.c:(.text+0x10d): undefined reference to `PQclear'
testlibpq.c:(.text+0x121): undefined reference to `PQexec'
...等等我必须做什么应该做些什么来纠正工作?
I'm installing postgresql 8.4 in Debian, put program testlibpq.c from http://www.postgresql.org/docs/9.0/interactive/libpq-example.html to directory which have file libpq-fe.h, but after compilation gcc write me
testlibpq.c:(.text+0x4a): undefined reference to `PQconnectdb'
testlibpq.c:(.text+0x5a): undefined reference to `PQstatus'
testlibpq.c:(.text+0x6f): undefined reference to `PQerrorMessage'
testlibpq.c:(.text+0xa9): undefined reference to `PQexec'
testlibpq.c:(.text+0xb9): undefined reference to `PQresultStatus'
testlibpq.c:(.text+0xcf): undefined reference to `PQerrorMessage'
testlibpq.c:(.text+0xf5): undefined reference to `PQclear'
testlibpq.c:(.text+0x10d): undefined reference to `PQclear'
testlibpq.c:(.text+0x121): undefined reference to `PQexec'
... e.t.c. What I must suppose to do to correct work?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看起来您没有链接 PostgreSQL 库。您应该使用如下内容编译
testlibpq.c
:-lpq
告诉链接器链接到 PostgreSQL 库,这就是PQconnectdb
和朋友来自。您可能还需要告诉编译器在哪里可以找到库和头文件,如果是这样,那么类似这样的事情应该解决这个问题:
Looks like you're not linking the PostgreSQL library. You should be compiling
testlibpq.c
with something like this:The
-lpq
tells the linker to link against the PostgreSQL library and that's wherePQconnectdb
and friends come from.You may need to tell the compiler where to find the libraries and headers as well, if so then something like this should sort that out: