help for compiling libpq sample program

help for compiling libpq sample program

Post by mike » Wed, 12 Sep 2001 06:08:03



"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;

Quote:}

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;

Quote:}

Thank you in advance.

--
Best Regards,

Mike
Web Programmer
TKO Systems, Ltd.

 
 
 

1. Help compiling Oracle 7.1.6 Pro*C sample programs on AIX 4.2

All,

Has anyone tried to compile the sample programs for Oracle 7.1.6.2 on an
IBM AIX 4.2 system?  We are having some problems compiling some of our
existing C programs on this platform.  When I tried to compile the sample
programs I get the results shown below (sorry for the long message).  Has
anyone successfully done this before, or can someone provide clues to what
we could try to get it to work?

Thanks,
Brian
--------------------------------------------------
$ make -f proc.mk sample6
        /u01/home/dba/oracle/product/7.1.6/bin/proc  iname=sample6.pc

Pro*C: Release 2.0.6.0.0 - Production on Thu May  1 18:08:16 1997

Copyright (c) Oracle Corporation 1979, 1994.  All rights reserved.

System default option values taken from:
/u01/home/dba/oracle/product/7.1.6/proc
/pmscfg.h

        make -f /u01/home/dba/oracle/product/7.1.6/proc/lib/proc.mk
OBJS=sample6
.o EXE=sample6 build
        /u01/home/dba/oracle/product/7.1.6/bin/proc dbms=v6_char
iname=sample6.p
c

Pro*C: Release 2.0.6.0.0 - Production on Thu May  1 18:08:17 1997

Copyright (c) Oracle Corporation 1979, 1994.  All rights reserved.

System default option values taken from:
/u01/home/dba/oracle/product/7.1.6/proc
/pmscfg.h

        oraxlc -I. -O -I/u01/home/dba/oracle/product/7.1.6/sqllib/public -c
samp
le6.c
oraxlc -L/u01/home/dba/oracle/product/7.1.6/lib -o sample6 sample6.o -lsql
/u01/
home/dba/oracle/product/7.1.6/lib/osntab.o -lsqlnet -lora -lsqlnet -lora
-lnlsrt
l -lcv6 -lcore -lnlsrtl -lcv6 -lcore -lm -lld -lm /lib/crt0.o -lc
-bI:/u01/home/
dba/oracle/product/7.1.6/lib/mili.exp
ld: 0711-224 WARNING: Duplicate symbol: .__quous
ld: 0711-224 WARNING: Duplicate symbol: __quous
ld: 0711-224 WARNING: Duplicate symbol: .__divus
ld: 0711-224 WARNING: Duplicate symbol: __divus
ld: 0711-224 WARNING: Duplicate symbol: .__divss
ld: 0711-224 WARNING: Duplicate symbol: __divss
ld: 0711-224 WARNING: Duplicate symbol: .__quoss
ld: 0711-224 WARNING: Duplicate symbol: __quoss
ld: 0711-224 WARNING: Duplicate symbol: .__mulh
ld: 0711-224 WARNING: Duplicate symbol: __mulh
ld: 0711-345 Use the -bloadmap or -bnoquiet option to obtain more
information.
ld: 0711-317 ERROR: Undefined symbol: .sltsini
ld: 0711-317 ERROR: Undefined symbol: .sltster
ld: 0711-317 ERROR: Undefined symbol: .upipi

.....  etc.  .....

--
Brian M. Biggs              http://www.cincom.com/
Cincom Systems, Inc.        voice: (513)677-7661

2. Upgrade to INFORMIX 7.1

3. Compile IBM C++ sample program DSN8EUDN?

4. LI - Strong SQL/Sybase Server on Unix or NT client (Cpp/C a plus)

5. pgsql/src/interfaces/libpq libpq-fe.h libpq-int.h

6. Internal server error using XML Templates

7. pgsql/src/interfaces/libpq (fe-connect.c libpq-fe.h libpq-int.h libpqdll.def)

8. SQL Problems from VBA- Help Please!

9. compile libpq prog with mingw32

10. Rappel?: libpq compile error

11. libpq compile error

12. pgsql/src/backend/libpq pg_hba.conf.sample

13. compiling libpq++ on Solaris with Sun SPRO6U2 (fixed