pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
error in code
4+ messages / 3 participants
[nested] [flat]

* error in code
@ 2003-12-08 13:55 Ashok Chauhan <ashok@kalculate.com>
  2003-12-08 13:58 ` Re: error in code Oliver Elphick <olly@lfix.co.uk>
  0 siblings, 1 reply; 4+ messages in thread

From: Ashok Chauhan @ 2003-12-08 13:55 UTC (permalink / raw)
  To: pgsql-admin

hi
*********************************
# include <stdio.h>
# include <stdlib.h>
# include </usr/include/libpq-fe.h>
# include </usr/include/libpq/libpq-fs.h>

int main()
{
        PGresult *result;
        PGconn *conn;
        int feild;
        conn = PQconnectdb ("ashok");
        result = PQexec (conn, "select * from bill");
        feild = PQntuples (result);
        printf("%d",feild);
        PQclear (result);
        PQfinish (conn);
        printf("hello");
        return 1;


}

I make the following code with the make command but give the following
the errors:-

/tmp/ccUWs9W9.o: In function `main':
/tmp/ccUWs9W9.o(.text+0x19): undefined reference to `PQconnectdb'
/tmp/ccUWs9W9.o(.text+0x2f): undefined reference to `PQexec'
/tmp/ccUWs9W9.o(.text+0x40): undefined reference to `PQntuples'
/tmp/ccUWs9W9.o(.text+0x64): undefined reference to `PQclear'
/tmp/ccUWs9W9.o(.text+0x72): undefined reference to `PQfinish'
collect2: ld returned 1 exit status
make: *** [aa] Error 1

plz help me.



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: error in code
  2003-12-08 13:55 error in code Ashok Chauhan <ashok@kalculate.com>
@ 2003-12-08 13:58 ` Oliver Elphick <olly@lfix.co.uk>
  0 siblings, 0 replies; 4+ messages in thread

From: Oliver Elphick @ 2003-12-08 13:58 UTC (permalink / raw)
  To: Ashok Chauhan <ashok@kalculate.com>; +Cc: pgsql-admin

On Mon, 2003-12-08 at 13:55, Ashok Chauhan wrote:
> I make the following code with the make command but give the following
> the errors:-
> 
> /tmp/ccUWs9W9.o: In function `main':
> /tmp/ccUWs9W9.o(.text+0x19): undefined reference to `PQconnectdb'
> /tmp/ccUWs9W9.o(.text+0x2f): undefined reference to `PQexec'
> /tmp/ccUWs9W9.o(.text+0x40): undefined reference to `PQntuples'
> /tmp/ccUWs9W9.o(.text+0x64): undefined reference to `PQclear'
> /tmp/ccUWs9W9.o(.text+0x72): undefined reference to `PQfinish'
> collect2: ld returned 1 exit status
> make: *** [aa] Error 1

These are link errors.  You need to add -lpq to the link command line
(and possibly -Lpath for the libpq library path as well).

-- 
Oliver Elphick                                Oliver.Elphick@lfix.co.uk
Isle of Wight, UK                             http://www.lfix.co.uk/oliver
GPG: 1024D/3E1D0C1C: CA12 09E0 E8D5 8870 5839  932A 614D 4C34 3E1D 0C1C
                 ========================================
     "For I am the LORD your God; ye shall therefore  
      sanctify yourselves, and ye shall be holy; for I am 
      holy."          Leviticus 11:44 




^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* error in code
@ 2003-12-10 05:26 Ashok Chauhan <ashok@kalculate.com>
  2003-12-11 01:57 ` Re: error in code Stephen Powell <stephen_powell@optusnet.com.au>
  0 siblings, 1 reply; 4+ messages in thread

From: Ashok Chauhan @ 2003-12-10 05:26 UTC (permalink / raw)
  To: pgsql-admin


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

int main()
{
        PGresult *result;
        PGconn *conn;
        int feild;
        printf("successful");
        conn = PQconnectdb ("ashok");
        result = PQexec (conn, "select * from bill");
        feild = PQntuples (result);
        printf("%d",feild);
        PQclear (result);
        PQfinish (conn);
        printf("hello");
        return 1;


}

I written a code and compile with following command, it complied and
create 'a.out' file but when i run the a.out it give nothing.
command:- "gcc program.c -I /usr/include/pgsql/include -L
/usr/lib/libpq.a -lpq"

plz help me.
Ashok



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: error in code
  2003-12-10 05:26 error in code Ashok Chauhan <ashok@kalculate.com>
@ 2003-12-11 01:57 ` Stephen Powell <stephen_powell@optusnet.com.au>
  0 siblings, 0 replies; 4+ messages in thread

From: Stephen Powell @ 2003-12-11 01:57 UTC (permalink / raw)
  To: pgsql-admin

On 10 Dec 2003, ashok@kalculate.com wrote:

> I written a code

[...]

Checking for errors is good:

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

int main()
{
        PGresult *result = NULL;
        PGconn *conn = NULL;
        int feild;
        printf("successful");
        conn = PQconnectdb ("ashok");
  if (!conn || CONNECTION_BAD == PQstatus(conn)) {
    fprintf(stderr, "Connection to database failed.\n");
    fprintf(stderr, "%s", PQerrorMessage(conn));
    exit(EXIT_FAILURE);
  }
        result = PQexec (conn, "select * from bill");
  if (!result || PGRES_TUPLES_OK != PQresultStatus(result)) {
    fprintf(stderr, "select command returned no tuples\n");
    fprintf(stderr, "%s", PQerrorMessage(conn));
    exit(EXIT_FAILURE);
  }
        feild = PQntuples (result);
        printf("%d",feild);
        PQclear (result);
        PQfinish (conn);
        printf("hello");
        return EXIT_SUCCESS;
}

> when i run the a.out it give nothing.

Not even "successful" or "hello" from the printfs?

> plz help me.

Download the programmers manual from here <http://www.postgresql.org/docs/;

-- 
Stephen Powell




^ permalink  raw  reply  [nested|flat] 4+ messages in thread


end of thread, other threads:[~2003-12-11 01:57 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2003-12-08 13:55 error in code Ashok Chauhan <ashok@kalculate.com>
2003-12-08 13:58 ` Oliver Elphick <olly@lfix.co.uk>
2003-12-10 05:26 error in code Ashok Chauhan <ashok@kalculate.com>
2003-12-11 01:57 ` Stephen Powell <stephen_powell@optusnet.com.au>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox