#include<stdio.h> #include<stdlib.h> #include<libpq-fe.h> #include <string.h> int main() { PGconn *conn; const char *conninfo="host=localhost dbname=cloud user=cloud password=cloud"; // char conninfo[100]; // sprintf(conninfo,"dbname=%s user=%s password=%s","cloud","cloud","cloud"); conn=PQconnectdb(conninfo); if(PQstatus(conn)==CONNECTION_BAD) { fprintf(stderr,"connection to %s failed",conninfo); PQerrorMessage(conn); } else printf("connection ok"); PQfinish(conn); return 0; }
编译问题:http://www.cnblogs.com/xfiver/archive/2012/02/17/2355642.html
gcc编译:gcc -I /usr/include/postgresql/ postgresql.c -o pgsql -lpq
yum install postgresql-devel
如果没有include 和 lib 两个目录...... 说明你还没装开发devel包 redhat上应该有其开发包 |