I am a newbie to postgres FE programming. I am trying to connect to Postgres db like
main(int argc, char **argv)
const char *conninfo;
extern PGconn *PQconnectStart(const char *conninfo);
if (argc > 1)
conninfo = argv;
conninfo = "dbname = table";
/* Make a connection to the database */
conn = PQconnectdb(conninfo);
/* Check to see that the backend connection was successfully made */
if (PQstatus(conn) != CONNECTION_OK)
fprintf(stderr, "Connection to database failed: %s",
I compiled it just like ordinary C pgms, using
gcc <My program.c>
All the functions like PQconnectdb() are defined in libpq-fe.h
Now my compiler is throwing error like
undefined reference to `PQconnectdb'
But this is defined in the header file.... Again I tried copying the entire header file in my program. ( All the defenitions are now in the program itself)
Again it is showing the undefined reference problem..............
What could be wrong????
please help me
Do I need to add any extra options while compiling?