Thread: problems in compiling

problems in compiling

From
"Mathew Chandy"
Date:
Hello sir,
 
  Whenever I compile the following sample code
 

# include <stdio.h>
# include <pgsql/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; */
.........
 
}
 
 
i get a compilation error which is of the following
 
/tmp/ccTCPDUs.o(.text+0x77): undefined reference to `PQstatus'
/tmp/ccTCPDUs.o(.text+0xa1): undefined reference to `PQerrorMessage'
/tmp/ccTCPDUs.o(.text+0xd4): undefined reference to `PQexec'
/tmp/ccTCPDUs.o(.text+0xeb): undefined reference to `PQresultStatus'
/tmp/ccTCPDUs.o(.text+0x118): undefined reference to `PQclear'
/tmp/ccTCPDUs.o(.text+0x130): undefined reference to `PQclear'
/tmp/ccTCPDUs.o(.text+0x141): undefined reference to `PQexec'
/tmp/ccTCPDUs.o(.text+0x158): undefined reference to `PQresultStatus'
/tmp/ccTCPDUs.o(.text+0x180): undefined reference to `PQclear'
/tmp/ccTCPDUs.o(.text+0x198): undefined reference to `PQclear'
/tmp/ccTCPDUs.o(.text+0x1a9): undefined reference to `PQexec'
/tmp/ccTCPDUs.o(.text+0x1c0): undefined reference to `PQresultStatus'
/tmp/ccTCPDUs.o(.text+0x1e8): undefined reference to `PQclear'
/tmp/ccTCPDUs.o(.text+0x200): undefined reference to `PQnfields'
/tmp/ccTCPDUs.o(.text+0x229): undefined reference to `PQfname'
/tmp/ccTCPDUs.o(.text+0x265): undefined reference to `PQntuples'
/tmp/ccTCPDUs.o(.text+0x29d): undefined reference to `PQgetvalue'
/tmp/ccTCPDUs.o(.text+0x2d7): undefined reference to `PQclear'
/tmp/ccTCPDUs.o(.text+0x2e8): undefined reference to `PQexec'
/tmp/ccTCPDUs.o(.text+0x2f9): undefined reference to `PQclear'
/tmp/ccTCPDUs.o(.text+0x30a): undefined reference to `PQexec'
/tmp/ccTCPDUs.o(.text+0x31b): undefined reference to `PQclear'
/tmp/ccTCPDUs.o(.text+0x327): undefined reference to `PQfinish'
 
what is the reason . i use the folowing command line cc file.c
 
thanks in advance
 
Mathew
 

Re: problems in compiling

From
bmccoy@chapelperilous.net
Date:
On Thu, 5 Oct 2000, Mathew Chandy wrote:

> i get a compilation error which is of the following
>
> /tmp/ccTCPDUs.o(.text+0x77): undefined reference to `PQstatus'

...

>
> what is the reason . i use the folowing command line cc file.c

It's trying to resolve external references (link) in your executable but
you haven't told it to link against the Postgres libraries.  Try

cc file.c -lpq

Brett W. McCoy
                                              http://www.chapelperilous.net
---------------------------------------------------------------------------
The Kennedy Constant:
    Don't get mad -- get even.