Problem compiling program

From: mskott(at)image(dot)dk (Martin Sktt)
To: pgsql-interfaces(at)postgreSQL(dot)org
Subject: Problem compiling program
Date: 1999-05-03 21:06:04
Message-ID: slrn7is3te.13o.mskott@jumbo.skott.dk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-interfaces


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 Sktt
mskott(at)image(dot)dk

Browse pgsql-interfaces by date

  From Date Subject
Next Message Hugh Lawson 1999-05-03 21:45:21 Re: [INTERFACES] Field types (was Re: Return value of int)
Previous Message barreiro 1999-05-03 20:09:32 Error linking C++ code.