linux下postgresql的c程序編譯問題


linux下c程序使用postgresql 8.4連接數據庫時編譯出現的問題。

1.

問題:In function `main':

`PGconn' undeclared (first use in this function)

`PGresult' undeclared (first use in this function)

`CONNECTION_BAD' undeclared (first use in this function)

`PGRES_COMMAND_OK' undeclared (first use in this function)

`PGRES_TUPLES_OK' undeclared (first use in this function)

 

出現此問題,為缺少#include <libpq-fe.h>

2.

問題:libpq-fe.h: No such file or directory
解決:系統未查找到libpq-fe.h,需要指定其目錄
方式1:gcc -c -I/usr/local/pgsql/include test.c
方式2:Makefile文件中,CPPFLAGS += -I/usr/local/pgsql/include

3.編譯.c至.o通過,但鏈接時出現如下問題
In function `main':
undefined reference to `PQsetdbLogin'
undefined reference to `PQstatus'
undefined reference to `PQerrorMessage'
解決:此為缺少鏈接所需的庫文件導致,需手動指定其目錄

 

gcc -o test test1.o test2.o -L/usr/local/pgsql/lib -lpq

 

 

編譯成功。

 

參考:http://www.postgresql.org/docs/8.4/interactive/libpq-build.html

 總結:更多詳細至官方搜索解決方案,google時多使用site:來限定搜索范圍,更快速找到問題解決方法。

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM