Re: getting started with libpq and postgresql

Lists: pgsql-interfaces
From: "Damar Thapa" <damar(at)sst(dot)com(dot)hk>
To: <pgsql-interfaces(at)postgresql(dot)org>
Subject: getting started with libpq and postgresql
Date: 2001-11-01 09:45:48
Message-ID: 000f01c162b9$fe99ab00000f01c162b9$fe99ab00$0dffa8c0@win2kdffa8c0@win2k
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-interfaces

Hi!,

I am trying to use libpq (C interface) to write client program to access PostGreSQL database.

I copied an example program from PostgreSQL: Introduction and Concepts by Bruce Momjian.

To compile the above said program, I did:

gcc -o ctest ctest.c /*I named the copied program as ctest.c*/

I got an error message, saying "libpq-fe.h not found".

In my linux RH7.1, I found libpq-fe.h in /usr/include/pgsql directory, so I replace the line '#include "libpq-fe.h"' in ctest.c with'#include "/usr/include/pgsql/libpq-fe.h"'. I did not get the above-said error, but the followings:

/tmp/ccgwexRo.0: In function 'main':

/tmp/ccgwexRr.o(.txt+0x12): undefined reference to 'PQconnectdb'
/tmp/ccgwexRr.o(.txt+0x2b): undefined reference to 'PQstatus'
/tmp/ccgwexRr.o(.txt+0x5c): undefined reference to 'PQerrorMessage'
/tmp/ccgwexRr.o(.txt+0xd4): undefined reference to 'PQexec'

7 more lines like these.

Having these errors, I obviously have not done things correctly.

Do I have to do any setting in gcc or compilation has to be done differently.

Any help would be highly appreciated.

With regards,

Damar Thapa


From: Antonio Sergio de Mello e Souza <asergioz(at)bol(dot)com(dot)br>
To: Damar Thapa <damar(at)sst(dot)com(dot)hk>
Cc: pgsql-interfaces(at)postgresql(dot)org
Subject: Re: getting started with libpq and postgresql
Date: 2001-11-01 20:45:33
Message-ID: 3BE1B46D.6000202@bol.com.br
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-interfaces

Damar Thapa wrote:

> In my linux RH7.1, I found libpq-fe.h in /usr/include/pgsql directory,
> so I replace the line '#include "libpq-fe.h"' in ctest.c
> with'#include "/usr/include/pgsql/libpq-fe.h"'. I did not get the
> above-said error, but the followings:
>
>
>
> /tmp/ccgwexRo.0: In function 'main':
>
>
>
> /tmp/ccgwexRr.o(.txt+0x12): undefined reference to 'PQconnectdb'
>
> /tmp/ccgwexRr.o(.txt+0x2b): undefined reference to 'PQstatus'
> /tmp/ccgwexRr.o(.txt+0x5c): undefined reference to 'PQerrorMessage'
>
> /tmp/ccgwexRr.o(.txt+0xd4): undefined reference to 'PQexec'
>
>
>
> Do I have to do any setting in gcc or compilation has to be done
> differently.
>
Hi,

You need to tell the compiler where the include files and libraries are.
Try this command:

gcc -I /usr/include/pgsql -L /usr/lib/pgsql -lpq -o ctest ctest.c

The -I option says that the include files are located at
/usr/include/pgsql, the -L says that the library can be found at
/usr/lib/pgsql and the -lpq option shows that you're using the pq
library. This is just an example, the actual paths in your system can be
different.
Also, you need to check the contents of the /etc/ld.so.conf file. Add a
line with the path to the library if it isn't already there. Remember to
run, as root, the command /sbin/ldconfig if you change that file.

Regards,

Antonio Sergio