繁体   English   中英

Debian中库libpq的问题

[英]Problem with library libpq in Debian

我正在Debian中安装PostgreSQL 8.4,将来自http://www.postgresql.org/docs/9.0/interactive/libpq-example.html的程序testlibpq.c放到具有文件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' 

...等我必须要做什么才能纠正工作?

看起来您没有链接PostgreSQL库。 您应该使用以下内容编译testlibpq.c

gcc -o testlibpq testlibpq.c -lpq

-lpq告诉链接器链接到PostgreSQL库,这就是PQconnectdb和朋友来自的地方。

您可能需要告诉编译器在哪里也可以找到库和标头,如果是这样,则应将以下内容整理出来:

gcc -o testlibpq -I$(pg_config --includedir) -L$(pg_config --libdir) -o testlibpq $(pg_config --libs)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM