Hi folks,
I am a newbie to postgres FE programming. I am trying to connect to Postgres db like
Code:
#include <stdio.h>
#include "pgsql/libpq-fe.h"
int
main(int argc, char **argv)
{
const char *conninfo;
PGconn *conn;
PGresult *res;
extern PGconn *PQconnectStart(const char *conninfo);
if (argc > 1)
conninfo = argv[1];
else
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",
PQerrorMessage(conn));
exit_nicely(conn);
}
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?