C & C ++Program Problem

Started by Arindam Haldaralmost 24 years ago6 messagesgeneral
Jump to latest
#1Arindam Haldar
arindamhaldar@hotpop.com

hi all,
am trying to use C & C++ libraries with postgresql 7.2.
while compiling a sample programe(attached) there were thse errors
encounterd !..

[arindam@my src]$
[arindam@my src]$ gcc egTry.c
/tmp/ccTLiExh.o: In function `main':
/tmp/ccTLiExh.o(.text+0x12): undefined reference to `PQconnectdb'
/tmp/ccTLiExh.o(.text+0x2b): undefined reference to `PQstatus'
/tmp/ccTLiExh.o(.text+0x5c): undefined reference to `PQerrorMessage'
/tmp/ccTLiExh.o(.text+0xac): undefined reference to `PQexec'
/tmp/ccTLiExh.o(.text+0xc5): undefined reference to `PQresultStatus'
/tmp/ccTLiExh.o(.text+0xf3): undefined reference to `PQclear'
/tmp/ccTLiExh.o(.text+0x104): undefined reference to `PQfinish'
/tmp/ccTLiExh.o(.text+0x12e): undefined reference to `PQntuples'
/tmp/ccTLiExh.o(.text+0x159): undefined reference to `PQgetvalue'
/tmp/ccTLiExh.o(.text+0x186): undefined reference to `PQclear'
/tmp/ccTLiExh.o(.text+0x197): undefined reference to `PQfinish'
collect2: ld returned 1 exit status
[arindam@my src]$

lib & include dir are in /usr/lib/pgsql-7.2 & /usr/include/pgsql-7.2.
i have tried to compliethis programme with RH7.2(with postgres rpm & a
configured from tar file)..
i need help pls... i want to use C or C++
thanking u in advance
A.H

Attachments:

egTry1.ctext/plain; name=egTry1.cDownload
In reply to: Arindam Haldar (#1)
Re: [INTERFACES] C & C ++Program Problem

On Thu, May 16, 2002 at 04:07:38AM +0530, Arindam Haldar wrote:

am trying to use C & C++ libraries with postgresql 7.2.
while compiling a sample programe(attached) there were thse errors
encounterd !..

Are you linking your program with libpq? It would seem that this may
not be the case, but you need to.

Jeroen

#3Martijn van Oosterhout
kleptog@svana.org
In reply to: Arindam Haldar (#1)
Re: C & C ++Program Problem

On Thu, May 16, 2002 at 04:07:38AM +0530, Arindam Haldar wrote:

hi all,
am trying to use C & C++ libraries with postgresql 7.2.
while compiling a sample programe(attached) there were thse errors
encounterd !..

[arindam@my src]$
[arindam@my src]$ gcc egTry.c

Try: gcc egTry.c -lpq

(or is it -lpg?)

The compiler needs to know which library contains the symbols you're
missing.

HTH,
--
Martijn van Oosterhout <kleptog@svana.org> http://svana.org/kleptog/

Show quoted text

Canada, Mexico, and Australia form the Axis of Nations That
Are Actually Quite Nice But Secretly Have Nasty Thoughts About America

#4Arindam Haldar
arindamhaldar@hotpop.com
In reply to: Martijn van Oosterhout (#3)
Re: C & C ++Program Problem

hi,
thanx for the hint. am re-entering c programming from DOS world !--my
apologies as am again a learner. 1 more Query on to this.
POstgres-7.2 was not configured with-->--with-gnu-ld , which i just saw
is default set to no... So can that be problem while compling C & C++
prorgrames ?
thanx again in advance for ur help.
A.H

Nigel J. Andrews wrote:

You need to read the error messages. It's not a postgres issue it's a
linking
issue. Try giving the -lpq flag to gcc.

On Thu, 16 May 2002, Arindam Haldar wrote:

hi all,
am trying to use C & C++ libraries with postgresql 7.2.
while compiling a sample programe(attached) there were thse errors
encounterd !..

[arindam@my src]$
[arindam@my src]$ gcc egTry.c
/tmp/ccTLiExh.o: In function `main':
/tmp/ccTLiExh.o(.text+0x12): undefined reference to `PQconnectdb'
/tmp/ccTLiExh.o(.text+0x2b): undefined reference to `PQstatus'
/tmp/ccTLiExh.o(.text+0x5c): undefined reference to `PQerrorMessage'
/tmp/ccTLiExh.o(.text+0xac): undefined reference to `PQexec'
/tmp/ccTLiExh.o(.text+0xc5): undefined reference to `PQresultStatus'
/tmp/ccTLiExh.o(.text+0xf3): undefined reference to `PQclear'
/tmp/ccTLiExh.o(.text+0x104): undefined reference to `PQfinish'
/tmp/ccTLiExh.o(.text+0x12e): undefined reference to `PQntuples'
/tmp/ccTLiExh.o(.text+0x159): undefined reference to `PQgetvalue'
/tmp/ccTLiExh.o(.text+0x186): undefined reference to `PQclear'
/tmp/ccTLiExh.o(.text+0x197): undefined reference to `PQfinish'
collect2: ld returned 1 exit status
[arindam@my src]$

lib & include dir are in /usr/lib/pgsql-7.2 & /usr/include/pgsql-7.2.
i have tried to compliethis programme with RH7.2(with postgres rpm & a
configured from tar file)..
i need help pls... i want to use C or C++
thanking u in advance
A.H

#5Arindam Haldar
arindamhaldar@hotpop.com
In reply to: Arindam Haldar (#4)
Re: [INTERFACES] C & C ++Program Problem

on my RedHat 7.2 i have inserted these lines in the file /etc/ld.so.conf
/usr/lib/pgsql-7.2
using gcc -lpq egtry.c gives error-->
/usr/bin/ld: cannot find -lpq
collect2: ld reurned 1 exit status

am very newto c , can u tellhow to use -lpq ??
thanx in anticipation
A.H

Ted Petrosky wrote:

Show quoted text

I was having the same problems. Do you have the momjiam book
PostgreSQL? He gives examples of compiling C and C++ programs complete
with the command line to start compiling (on page 195). Take a look at it (I
think it is also online). You are missing the linking flag that tells the linker
where the libpq.a and libpq++.a files live. libpq.a and libpq++.a is where those
symbols are defined.

Ted

-----Original Message-----
From: Arindam Haldar <arindamhaldar@hotpop.com>
To: pgsql-interfaces@postgresql.org, pgsql-general@postgresql.org,
nandrews@investsystems.co.uk
Date: Thu, 16 May 2002 12:23:19 +0530
Subject: Re: [INTERFACES] C & C ++Program Problem

hi,
thanx for the hint. am re-entering c programming from DOS world !--my
apologies as am again a learner. 1 more Query on to this.
POstgres-7.2 was not configured with-->--with-gnu-ld , which i just saw
is default set to no... So can that be problem while compling C & C++
prorgrames ?
thanx again in advance for ur help.
A.H

Nigel J. Andrews wrote:

You need to read the error messages. It's not a postgres issue it's a
linking
issue. Try giving the -lpq flag to gcc.

On Thu, 16 May 2002, Arindam Haldar wrote:

hi all,
am trying to use C & C++ libraries with postgresql 7.2.
while compiling a sample programe(attached) there were thse errors
encounterd !..

[arindam@my src]$
[arindam@my src]$ gcc egTry.c
/tmp/ccTLiExh.o: In function `main':
/tmp/ccTLiExh.o(.text+0x12): undefined reference to `PQconnectdb'
/tmp/ccTLiExh.o(.text+0x2b): undefined reference to `PQstatus'
/tmp/ccTLiExh.o(.text+0x5c): undefined reference to `PQerrorMessage'
/tmp/ccTLiExh.o(.text+0xac): undefined reference to `PQexec'
/tmp/ccTLiExh.o(.text+0xc5): undefined reference to `PQresultStatus'
/tmp/ccTLiExh.o(.text+0xf3): undefined reference to `PQclear'
/tmp/ccTLiExh.o(.text+0x104): undefined reference to `PQfinish'
/tmp/ccTLiExh.o(.text+0x12e): undefined reference to `PQntuples'
/tmp/ccTLiExh.o(.text+0x159): undefined reference to `PQgetvalue'
/tmp/ccTLiExh.o(.text+0x186): undefined reference to `PQclear'
/tmp/ccTLiExh.o(.text+0x197): undefined reference to `PQfinish'
collect2: ld returned 1 exit status
[arindam@my src]$

lib & include dir are in /usr/lib/pgsql-7.2 & /usr/include/pgsql-7.2.
i have tried to compliethis programme with RH7.2(with postgres rpm & a
configured from tar file)..
i need help pls... i want to use C or C++
thanking u in advance
A.H

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to

majordomo@postgresql.org

#6Doug McNaught
doug@wireboard.com
In reply to: Arindam Haldar (#5)
Re: [INTERFACES] C & C ++Program Problem

Arindam Haldar <arindamhaldar@hotpop.com> writes:

on my RedHat 7.2 i have inserted these lines in the file /etc/ld.so.conf
/usr/lib/pgsql-7.2

This may or may not be necessary, but if you do it you need to run
'ldconfig' in order for it to take effect.

using gcc -lpq egtry.c gives error-->
/usr/bin/ld: cannot find -lpq
collect2: ld reurned 1 exit status

You need to add a -L flag to the compile so gcc looks in the right
place for libraries. Also, the '-lpq' should go *after* your source
file name. So:

gcc -o egtry egtry.c -L/usr/lib/pgsql-7.2 -lpq

That should get you a lot closer to working.

-Doug