Article View: alt.linux
Article #331Re: help: Undefined reference to '...'
From: David. E. Goble
Date: Sun, 27 May 2001 07:55
Date: Sun, 27 May 2001 07:55
179 lines
6747 bytes
6747 bytes
On Thu, 24 May 2001 07:52:32 GMT, goble@gtech (David. E. Goble) wrote:
>
Hi All;
I have redHat 6.2 (server install)
I am trying to do some programming.
How that I know how to save the error messages, here is what is
happening;
/*######## Here is the c file I am trying to compile and run #######*/
/*
* testlibpq.c Test the C version of Libpq, the Postgres frontend
* library.
*
*
*/
#include<stdio.h>
#include "libpq-fe.h"
void exit_nicely(PGconn *conn)
{
PQfinish(conn);
exit(1);
}
main()
{
char *pghost,
*pgport,
*pgoptions,
*pgtty;
char *dbName;
int nFields;
int i,
j;
/* FILE *debug; */
PGconn *conn;
PGresult *res;
/*
* begin, by setting the parameters for a backend connection if
the
* parameters are null, then the system will try to use reasonable
* defaults by looking up environment variables or, failing that,
* using hardwired constants
*/
pghost = NULL; /* host name of the backend server */
pgport = NULL; /* port of the backend server */
pgoptions = NULL; /* special options to start up the
backend
* server */
pgtty = NULL; /* debugging tty for the backend
server */
dbName = "template1";
/* make a connection to the database */
conn = PQsetdb(pghost, pgport, pgoptions, pgtty, dbName);
/*
* check to see that the backend connection was successfully made
*/
if (PQstatus(conn) == CONNECTION_BAD)
{
fprintf(stderr, "Connection to database '%s' failed.\n",
dbName);
fprintf(stderr, "%s", PQerrorMessage(conn));
exit_nicely(conn);
}
/* debug = fopen("/tmp/trace.out","w"); */
/* PQtrace(conn, debug); */
/* start a transaction block */
res = PQexec(conn, "BEGIN");
if (!res || PQresultStatus(res) != PGRES_COMMAND_OK)
{
fprintf(stderr, "BEGIN command failed\n");
PQclear(res);
exit_nicely(conn);
}
/*
* should PQclear PGresult whenever it is no longer needed to
avoid
* memory leaks
*/
PQclear(res);
/*
* fetch instances from the pg_database, the system catalog of
* databases
*/
res = PQexec(conn, "DECLARE mycursor CURSOR FOR select * from
pg_database");
if(!res || PQresultStatus(res) != PGRES_COMMAND_OK)
{
fprintf(stderr, "DECLARE CURSOR command failed\n");
PQclear(res);
exit_nicely(conn);
}
PQclear(res);
res = PQexec(conn, "FETCH ALL in mycursor");
if(!res || PQresultStatus(res) != PGRES_TUPLES_OK)
{
fprintf(stderr, "FETCH ALL command didn't return tuples
properly\n");
PQclear(res);
exit_nicely(conn);
}
/* first, print out the attribute names */
nFields = PQnfields(res);
for (i = 0; i<nFields; i++)
printf("%-15s", PQfname(res, i));
printf("\n\n");
/* next, print out the instances */
for (i = 0; i<PQntuples(res); i++)
{
for (j = 0; j<nFields; j++)
printf("%-15s", PQgetvalue(res, i, j));
printf("\n");
}
PQclear(res);
/* close the cursor */
res = PQexec(conn, "CLOSE mycursor");
PQclear(res);
/* commit the transaction */
res = PQexec(conn, "COMMIT");
PQclear(res);
/* close the connection to the database and cleanup */
PQfinish(conn);
/* fclose(debug); */
}
/*
This is how I am trying to do it;
gcc -O3 -o testlibpq testlibpq.c -I/usr/include/pgsql -Llibpq
2>testlibpq.txt
And here are the results
/tmp/cc2HM1Be.o: In function `exit_nicely':
/tmp/cc2HM1Be.o(.text+0x8): undefined reference to `PQfinish'
/tmp/cc2HM1Be.o: In function `main':
/tmp/cc2HM1Be.o(.text+0x66): undefined reference to `PQsetdbLogin'
/tmp/cc2HM1Be.o(.text+0x77): undefined reference to `PQstatus'
/tmp/cc2HM1Be.o(.text+0xa1): undefined reference to `PQerrorMessage'
/tmp/cc2HM1Be.o(.text+0xd4): undefined reference to `PQexec'
/tmp/cc2HM1Be.o(.text+0xeb): undefined reference to `PQresultStatus'
/tmp/cc2HM1Be.o(.text+0x118): undefined reference to `PQclear'
/tmp/cc2HM1Be.o(.text+0x130): undefined reference to `PQclear'
/tmp/cc2HM1Be.o(.text+0x141): undefined reference to `PQexec'
/tmp/cc2HM1Be.o(.text+0x158): undefined reference to `PQresultStatus'
/tmp/cc2HM1Be.o(.text+0x180): undefined reference to `PQclear'
/tmp/cc2HM1Be.o(.text+0x198): undefined reference to `PQclear'
/tmp/cc2HM1Be.o(.text+0x1a9): undefined reference to `PQexec'
/tmp/cc2HM1Be.o(.text+0x1c0): undefined reference to `PQresultStatus'
/tmp/cc2HM1Be.o(.text+0x1e8): undefined reference to `PQclear'
/tmp/cc2HM1Be.o(.text+0x200): undefined reference to `PQnfields'
/tmp/cc2HM1Be.o(.text+0x229): undefined reference to `PQfname'
/tmp/cc2HM1Be.o(.text+0x265): undefined reference to `PQntuples'
/tmp/cc2HM1Be.o(.text+0x29d): undefined reference to `PQgetvalue'
/tmp/cc2HM1Be.o(.text+0x2d7): undefined reference to `PQclear'
/tmp/cc2HM1Be.o(.text+0x2e8): undefined reference to `PQexec'
/tmp/cc2HM1Be.o(.text+0x2f9): undefined reference to `PQclear'
/tmp/cc2HM1Be.o(.text+0x30a): undefined reference to `PQexec'
/tmp/cc2HM1Be.o(.text+0x31b): undefined reference to `PQclear'
/tmp/cc2HM1Be.o(.text+0x327): undefined reference to `PQfinish'
collect2: ld returned 1 exit status
*/
Technical Details
Message-ID:
<3b10ae18.58847@news.adelaide.on.net>Path:
arc1-ca.pugleaf.net!archiver1.google.com!newsfeed.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!news1.optus.net.au!optus!yorrell.saard.net!duster.adelaide.on.net!203.48.5.183References:
<3b0bacc3.134395@news.adelaide.on.net>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10c696,e7efa684ec24a406 X-Google-Attributes: gid10c696,public X-Google-Thread: 102983,e7efa684ec24a406 X-Google-Attributes: gid102983,public X-Google-Thread: f9b51,e7efa684ec24a406 X-Google-Attributes: gidf9b51,public X-Google-Thread: 100c5f,e7efa684ec24a406 X-Google-Attributes: gid100c5f,public X-Google-ArrivalTime: 2001-05-27 00:47:43 PST From: goble@gtech (David. E. Goble) Newsgroups: alt.linux,aus.computers.linux,comp.os.linux.development.apps,comp.os.linux.setup Subject: Re: help: Undefined reference to '...' Date: Sun, 27 May 2001 07:55:05 GMT Sender: goble@kin.on.net (David. E. Goble) Organization: Gtech.Computing Reply-To: goble@gtech Message-ID: <3b10ae18.58847@news.adelaide.on.net> References: <3b0bacc3.134395@news.adelaide.on.net> X-Newsreader: Forte Free Agent 1.21/32.243 NNTP-Posting-Host: 203.48.5.183 X-Trace: 27 May 2001 17:17:41 +0950, 203.48.5.183 Lines: 179 Path: arc1-ca.pugleaf.net!archiver1.google.com!newsfeed.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!news1.optus.net.au!optus!yorrell.saard.net!duster.adelaide.on.net!203.48.5.183