Обсуждение: libpq connectivity
Hello,
I am working on Linux RH 6.0 platform.
I want use PostgreSQL as a backend. 'C' language as a front-end.
I am not able to connect to each other.
I am using libpq.
The program is :-
/*conn2.c*/
#include <stdio.h>
#include "/usr/include/pgsql/libpq-fe.h"
main()
{
char *pghost, *pgport, *pgoptions,*pgtty;
char *dbName;
PGconn *conn;
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);
}
The compiling is ok, but linking have error.
$ gcc conn2.c -c -o conn2
No error
The program compile and linking result :-
*****************
$ gcc conn2.c -o conn2
/tmp/cchKU26L.o: In function `main':
/tmp/cchKU26L.o(.text+0x47): undefined reference to `PQsetdbLogin'
collect2: ld returned 1 exit status
*****************
How to remove this linking error, or how to make link between PostgreSQL and
'C'?
Thanks in advance
Anuj
anuj wrote:
>
> Hello,
>
> I am working on Linux RH 6.0 platform.
> I want use PostgreSQL as a backend. 'C' language as a front-end.
> I am not able to connect to each other.
> I am using libpq.
> The program is :-
>
> /*conn2.c*/
> #include <stdio.h>
> #include "/usr/include/pgsql/libpq-fe.h"
> main()
> {
> char *pghost, *pgport, *pgoptions,*pgtty;
> char *dbName;
> PGconn *conn;
> 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);
> }
>
> The compiling is ok, but linking have error.
> $ gcc conn2.c -c -o conn2
> No error
>
> The program compile and linking result :-
> *****************
> $ gcc conn2.c -o conn2
> /tmp/cchKU26L.o: In function `main':
> /tmp/cchKU26L.o(.text+0x47): undefined reference to `PQsetdbLogin'
> collect2: ld returned 1 exit status
> *****************
>
> How to remove this linking error, or how to make link between PostgreSQL and
> 'C'?
> Thanks in advance
> Anuj
You have to include the libraries. -lpq
--
Dave Smith
Candata Systems Ltd.
(416) 493-9020
dave@candata.com
Someone mentioned that you had to include libpq, but you are also using the
wrong GCC command line. the -c switch tells gcc to just build an object
file, ignoring the main routine and not creating an actual executable
program. You want something like this:
$ gcc conn2.c -o conn2 -lpq
At 01:53 AM 7/7/00, anuj wrote:
>Hello,
>
>I am working on Linux RH 6.0 platform.
>I want use PostgreSQL as a backend. 'C' language as a front-end.
>I am not able to connect to each other.
>I am using libpq.
>The program is :-
>
>/*conn2.c*/
>#include <stdio.h>
>#include "/usr/include/pgsql/libpq-fe.h"
> main()
> {
> char *pghost, *pgport, *pgoptions,*pgtty;
> char *dbName;
> PGconn *conn;
> 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);
>}
>
>The compiling is ok, but linking have error.
>$ gcc conn2.c -c -o conn2
>No error
>
>The program compile and linking result :-
>*****************
>$ gcc conn2.c -o conn2
>/tmp/cchKU26L.o: In function `main':
>/tmp/cchKU26L.o(.text+0x47): undefined reference to `PQsetdbLogin'
>collect2: ld returned 1 exit status
>*****************
>
>How to remove this linking error, or how to make link between PostgreSQL and
>'C'?
>Thanks in advance
>Anuj