Hello
I'm tryuing to learn to use libpq but it is quite difficult when you are
unable to compile programs as I am ;-)
I get this error when I compile the program in the buttom of this message:
/usr/local/pgsql/lib/libpq.so: undefined reference to `crypt'
I use this command on my Red Hat Linux 5.2 system when i try to compile:
gcc -I/usr/local/pgsql/include -o lj lj.c -L/usr/local/pgsql/lib -lpq
My program looks like this: (it was included in an article in Linux Journal)
#include <libpq-fe.h>
#include <strings.h>
int
main(int argc, char** argv)
{ PGconn* conn; PGresult* result; int i; char* dbname = "tutorial"; conn = PQsetdb (NULL, NULL, NULL, NULL, dbname);
if(PQstatus(conn) == CONNECTION_BAD) { fprintf(stderr, "Connection to database '%S' failed.\n", dbname);
fprintf(stderr,"%S", PQerrorMessage(conn)); PQfinish(conn); exit(1); } result = PQexec(conn, "select * from
cities");if ((!result) || (PGRES_TUPLES_OK != PQresultStatus(result))) { fprintf(stderr, "Error sending
query.\nDetailed report: %s\n", PQerrorMessage(conn)); PQfinish(conn); exit(1); }
printf("name\t\tpopulation\taltitude\n\n");for (i = PQntuples(result)-1; i >= 0; i--) { printf("%s\t%s\t\t%s\n",
PQgetvalue(result,i,0), PQgetvalue(result,i,1), PQgetvalue(result,i,2)); }
}
--
Med venlig hilsen
Martin Sk�tt
mskott@image.dk