help for compiling libpq sample program

From: "mike" <mike(at)tkosys(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: help for compiling libpq sample program
Date: 2001-09-10 21:08:03
Message-ID: 9nja88$1vfr$1@news.tht.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

"cc -O -o pgsample pgsample.c -L/usr/local/pgsql/lib -lpq" went thru.

Then I did "make pgsample.o".

After that "make pgsample", this process gave me original errors:

pgsample.o: In function `main':
pgsample.o(.text+0x12): undefined reference to `PQconnectdb'
pgsample.o(.text+0x2b): undefined reference to `PQstatus'
pgsample.o(.text+0x5c): undefined reference to `PQerrorMessage'
pgsample.o(.text+0xd0): undefined reference to `PQexec'
pgsample.o(.text+0xe9): undefined reference to `PQresultStatus'
pgsample.o(.text+0x117): undefined reference to `PQclear'
pgsample.o(.text+0x128): undefined reference to `PQfinish'
pgsample.o(.text+0x152): undefined reference to `PQntuples'
pgsample.o(.text+0x17d): undefined reference to `PQgetvalue'
pgsample.o(.text+0x1aa): undefined reference to `PQclear'
pgsample.o(.text+0x1bb): undefined reference to `PQfinish'
collect2: ld returned 1 exit status
make: *** [pgsample] Error 1

Here is my code:

#include <stdio.h>
#include <stdlib.h>
#include "libpq-fe.h"

int main()
{

char state_code[3];
char query_string[256];
PGconn *conn;
PGresult *res;
int i;

conn = PQconnectdb("dbname=webcalendar");

if (PQstatus(conn) == CONNECTION_BAD)
{
fprintf(stderr, "Connection to database failed.\n");
fprintf(stderr, "%s", PQerrorMessage(conn));
exit(1);
}
printf("Enter a name of the city: ");
scanf("%2s", state_code);

sprintf(query_string,
"SELECT * \
FROM webcal_entry \
");

res = PQexec(conn, query_string);

if (PQresultStatus(res) != PGRES_TUPLES_OK)
{
fprintf(stderr, "SELECT query failed.\n");
PQclear(res);
PQfinish(conn);
exit(1);
}

for (i = 0; i<PQntuples(res); i++)
printf("%s\n", PQgetvalue(res, i, 0));

PQclear(res);
PQfinish(conn);
return 0;
}

Here is my C program:

#include <stdio.h>
#include <stdlib.h>
#include "libpq-fe.h"

int main()
{

char state_code[3];
char query_string[256];
PGconn *conn;
PGresult *res;
int i;

conn = PQconnectdb("dbname=webcalendar");

if (PQstatus(conn) == CONNECTION_BAD)
{
fprintf(stderr, "Connection to database failed.\n");
fprintf(stderr, "%s", PQerrorMessage(conn));
exit(1);
}
printf("Enter a name of the city: ");
scanf("%2s", state_code);

sprintf(query_string,
"SELECT * \
FROM webcal_entry \
");

res = PQexec(conn, query_string);

if (PQresultStatus(res) != PGRES_TUPLES_OK)
{
fprintf(stderr, "SELECT query failed.\n");
PQclear(res);
PQfinish(conn);
exit(1);
}

for (i = 0; i<PQntuples(res); i++)
printf("%s\n", PQgetvalue(res, i, 0));

PQclear(res);
PQfinish(conn);
return 0;
}

Thank you in advance.

--
Best Regards,

Mike
Web Programmer
TKO Systems, Ltd.

Browse pgsql-general by date

  From Date Subject
Next Message Lamar Owen 2001-09-10 21:09:09 Re: How to make a REALLY FAST db server?
Previous Message Trond Eivind =?iso-8859-1?q?Glomsr=F8d?= 2001-09-10 20:54:04 Re: How to make a REALLY FAST db server?