1.将库函数路径加入LD_LIBRARY_PATH中 vi /etc/profile export LD_LIBRARY_PATH=$GLOBUS_LOCATION/lib:/usr/local/pgsql/lib 2.C连接 #include #include #include int main() { PGconn *conn; const char *conn_str="host=localhost dbname=rftdatabase user=USER pssword=PWD port=5432"; conn=PQconnectdb(conn_str); if(PQstatus(conn)==CONNECTION_BAD) { fprintf(stderr,"connection to %s failed",conn_str); PQerrorMessage(conn); } else printf("connection ok"); PQfinish(conn); return EXIT_SUCCESS; } 3.编译 gcc -I /usr/local/pgsql/include -L /usr/local/pgsql/lib -l pq pgsql.c -o pgsql |