Home > Archive > PostgreSQL Discussion > September 2005 > postgresql and C++/C









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author postgresql and C++/C
vdm.fbsd@virgilio.it

2005-09-28, 7:23 am

Context:FREEBSD 5.4, postgresql 8.0.3

I'm not a C newbye and I'm
having a go at compiling my first, simple C(++) program:

#include
<libpq-fe.h>
int main()
{
PGconn *psql;
psql = PQconnectdb("hostaddr =
'127.0.0.1' port = '' dbname = 'curve' user = 'vi
return 0;
}

But
when
I compile it the following message pops up:

vicbsd# gcc -I
/usr/local/include prova.cpp -o prova
/var/tmp//cceNJFrs.o(.text+0x25):
In function `main':
: undefined reference to `PQconnectdb'
/var/tmp//cceNJFrs.o(.eh_frame+0x11): undefined reference to
`__gxx_personality_v
0'


What's wrong with it?
Ciao
Vittorio




---------------------------(end of broadcast)---------------------------
TIP 9: In versions below 8.0, the planner will ignore your desire to
choose an index scan if your joining column's datatypes do not
match

Martijn van Oosterhout

2005-09-28, 7:23 am

On Wed, Sep 28, 2005 at 10:11:45AM +0100, vdm.fbsd@virgilio.it wrote:
> Context:FREEBSD 5.4, postgresql 8.0.3
>
> I'm not a C newbye and I'm
> having a go at compiling my first, simple C(++) program:


1. If it's a C program, you should name the file .c otherwise gcc is
likely to consider it a c++ program.

2. If it's a c++ program, use g++ to compile and link to make sure you
get all the right libraries and paths.

3. Use -lpq to link to the postgresql client library. You may need a -L
so it looks in the right place.

Hope this helps,
--
Martijn van Oosterhout <kleptog@svana.org> http://svana.org/kleptog/
> Patent. n. Genius is 5% inspiration and 95% perspiration. A patent is a
> tool for doing 5% of the work and then sitting around waiting for someone
> else to do the other 95% so you can sue them.


Peter Wiersig

2005-09-28, 7:23 am

On Wed, Sep 28, 2005 at 10:11:45AM +0100, vdm.fbsd@virgilio.it wrote:
>
> vicbsd# gcc -I


Don't use gcc to compile C++. Use g++.

Peter

---------------------------(end of broadcast)---------------------------
TIP 3: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faq

vdm.fbsd@virgilio.it

2005-09-28, 7:23 am

I've just modified the extension with .c instead of .cpp and run:
vicbsd# gcc -I /usr/local/include/ prova.c -o prova -Lpq
/var/tmp//cc86RZZl.o(.text+0x25): In function `main':
: undefined
reference to `PQconnectdb'

Nothing seems to be changed!

Thanks
anyway.
Vittorio
----Messaggio originale----
Da: kleptog@svana.org
Data: 28-set-2005 11.44
A: "vdm.fbsd@virgilio.it"<vdm.fbsd@virgilio.it>
Cc: <pgsql-general@postgresql.org>
Ogg: Re: [GENERAL] postgresql and
C++/C

On Wed, Sep 28, 2005 at 10:11:45AM +0100, vdm.fbsd@virgilio.it
wrote:
> Context:FREEBSD 5.4, postgresql 8.0.3
>
> I'm not a C newbye

and I'm
> having a go at compiling my first, simple C(++) program:


1.
If it's a C program, you should name the file .c otherwise gcc is
likely to consider it a c++ program.

2. If it's a c++ program, use g++
to compile and link to make sure you
get all the right libraries and
paths.

3. Use -lpq to link to the postgresql client library. You may
need a -L
so it looks in the right place.

Hope this helps,
--
Martijn
van Oosterhout <kleptog@svana.org> http://svana.org/kleptog/
>

Patent. n. Genius is 5% inspiration and 95% perspiration. A patent is a
> tool for doing 5% of the work and then sitting around waiting for

someone
> else to do the other 95% so you can sue them.





---------------------------(end of broadcast)---------------------------
TIP 5: don't forget to increase your free space map settings

Martijn van Oosterhout

2005-09-28, 7:23 am

On Wed, Sep 28, 2005 at 10:59:04AM +0100, vdm.fbsd@virgilio.it wrote:
> I've just modified the extension with .c instead of .cpp and run:
> vicbsd# gcc -I /usr/local/include/ prova.c -o prova -Lpq
> /var/tmp//cc86RZZl.o(.text+0x25): In function `main':
> : undefined
> reference to `PQconnectdb'
>
> Nothing seems to be changed!


Pay attention to the case, it's -lpq, not -Lpq. -L is for *search paths*.
Please read the documentation.
http://www.postgresql.org/docs/7.4/...ibpq-build.html
--
Martijn van Oosterhout <kleptog@svana.org> http://svana.org/kleptog/
> Patent. n. Genius is 5% inspiration and 95% perspiration. A patent is a
> tool for doing 5% of the work and then sitting around waiting for someone
> else to do the other 95% so you can sue them.


shakahshakah@gmail.com

2005-09-28, 9:23 am

"vdm.fbsd@virgilio.it" wrote:
> I've just modified the extension with .c instead of .cpp and run:
> vicbsd# gcc -I /usr/local/include/ prova.c -o prova -Lpq
> /var/tmp//cc86RZZl.o(.text+0x25): In function `main':
> : undefined
> reference to `PQconnectdb'
>
> Nothing seems to be changed!
>
> Thanks
> anyway.
> Vittorio


You have your "-L" and "-l" options mixed up, probably should be
something like:
vicbsd# gcc -I/usr/local/include prova.c -o prova
-L/usr/local/pgsql/lib -lpq

Sponsored Links





Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive | Programming forum archive

Copyright 2008 droptable.com