Thread: erros when making examples in /src/test/examples

erros when making examples in /src/test/examples

From
Wei Wang
Date:
Hi,


I am just trying to make the frontend programs in /src/test/examples

make all gives errors:


gcc -O2 -Wall -Wmissing-prototypes -Wmissing-declarations -I../../../src/interfaces/libpq -I../../../src/include
-Wl,-rpath,/local/scratch-1/ww220/postgresql-7.1.3/lib testlibpq.c   -o testlibpq 
testlibpq.c: In function `exit_nicely':
testlibpq.c:14: warning: implicit declaration of function `exit'
/tmp/ccNom46z.o: In function `exit_nicely':
/tmp/ccNom46z.o(.text+0xa): undefined reference to `PQfinish'
/tmp/ccNom46z.o: In function `main':
/tmp/ccNom46z.o(.text+0x3c): undefined reference to `PQsetdbLogin'
/tmp/ccNom46z.o(.text+0x48): undefined reference to `PQstatus'
/tmp/ccNom46z.o(.text+0x69): undefined reference to `PQerrorMessage'
/tmp/ccNom46z.o(.text+0x99): undefined reference to `PQexec'
/tmp/ccNom46z.o(.text+0xa3): undefined reference to `PQresultStatus'
/tmp/ccNom46z.o(.text+0xc4): undefined reference to `PQclear'
/tmp/ccNom46z.o(.text+0xd9): undefined reference to `PQclear'
/tmp/ccNom46z.o(.text+0xe8): undefined reference to `PQexec'
/tmp/ccNom46z.o(.text+0xf2): undefined reference to `PQresultStatus'
/tmp/ccNom46z.o(.text+0x113): undefined reference to `PQclear'
/tmp/ccNom46z.o(.text+0x128): undefined reference to `PQclear'
/tmp/ccNom46z.o(.text+0x137): undefined reference to `PQexec'
/tmp/ccNom46z.o(.text+0x141): undefined reference to `PQresultStatus'
/tmp/ccNom46z.o(.text+0x164): undefined reference to `PQclear'
/tmp/ccNom46z.o(.text+0x17b): undefined reference to `PQnfields'
/tmp/ccNom46z.o(.text+0x192): undefined reference to `PQfname'
/tmp/ccNom46z.o(.text+0x1cf): undefined reference to `PQgetvalue'
/tmp/ccNom46z.o(.text+0x200): undefined reference to `PQntuples'
/tmp/ccNom46z.o(.text+0x210): undefined reference to `PQclear'
/tmp/ccNom46z.o(.text+0x21f): undefined reference to `PQexec'
/tmp/ccNom46z.o(.text+0x229): undefined reference to `PQclear'
/tmp/ccNom46z.o(.text+0x238): undefined reference to `PQexec'
/tmp/ccNom46z.o(.text+0x242): undefined reference to `PQclear'
/tmp/ccNom46z.o(.text+0x24b): undefined reference to `PQfinish'
collect2: ld returned 1 exit status
make: *** [testlibpq] Error 1

Afte searching on the net, I added -lpq but the result is not positive:

gcc -O2 -Wall -Wmissing-prototypes -Wmissing-declarations -I../../../src/interfaces/libpq -I../../../src/include
testlibpq.c  -o testlibpq -lpq 
testlibpq.c: In function `exit_nicely':
testlibpq.c:14: warning: implicit declaration of function `exit'
/usr/bin/ld: cannot find -lpq
collect2: ld returned 1 exit status

What am I missing here?


Many thanks,

Wei

Re: erros when making examples in /src/test/examples

From
Martijn van Oosterhout
Date:
On Thu, May 30, 2002 at 01:11:22PM +0100, Wei Wang wrote:
> Hi,
>
>
> I am just trying to make the frontend programs in /src/test/examples
>
> make all gives errors:
>
>
> gcc -O2 -Wall -Wmissing-prototypes -Wmissing-declarations -I../../../src/interfaces/libpq -I../../../src/include
-Wl,-rpath,/local/scratch-1/ww220/postgresql-7.1.3/lib testlibpq.c   -o testlibpq 

You need a -lpq in there somewhere.

> Afte searching on the net, I added -lpq but the result is not positive:
>
> gcc -O2 -Wall -Wmissing-prototypes -Wmissing-declarations -I../../../src/interfaces/libpq -I../../../src/include
testlibpq.c  -o testlibpq -lpq 
> testlibpq.c: In function `exit_nicely':
> testlibpq.c:14: warning: implicit declaration of function `exit'
> /usr/bin/ld: cannot find -lpq
> collect2: ld returned 1 exit status

Did you install it? Look around for a file named libpq.so. Add an option
-L/directory/containing/that/lib after the -I options.

HTH,
--
Martijn van Oosterhout   <kleptog@svana.org>   http://svana.org/kleptog/
> Canada, Mexico, and Australia form the Axis of Nations That
> Are Actually Quite Nice But Secretly Have Nasty Thoughts About America

Re: erros when making examples in /src/test/examples

From
Wei Wang
Date:
Thanks a lot.


It works:

gcc -O2 -Wall -Wmissing-prototypes -Wmissing-declarations -I../../../src/interfaces/libpq -I../../../src/include
-Wl,-rpath,/local/scratch-1/ww220/postgresql-7.1.3/lib -L/homes/ww220/myspace/postgresql-7.1.3/lib testlibpq.c   -o
testlibpq-lpq 
testlibpq.c: In function `exit_nicely':
testlibpq.c:14: warning: implicit declaration of function `exit'

I am a total newbie to almost everything. I put
export PATH=/local/scratch-1/ww220/myspace/postgresql-7.1.3/lib:$PATH
in .bash_profile and did ". .bash_profile". Is that different from putting
-L switch in gcc command?

Wei


On Thu, 30 May 2002 22:43:59 +1000
Martijn van Oosterhout <kleptog@svana.org> wrote:

> On Thu, May 30, 2002 at 01:11:22PM +0100, Wei Wang wrote:
> > Hi,
> >
> >
> > I am just trying to make the frontend programs in /src/test/examples
> >
> > make all gives errors:
> >
> >
> > gcc -O2 -Wall -Wmissing-prototypes -Wmissing-declarations -I../../../src/interfaces/libpq -I../../../src/include
-Wl,-rpath,/local/scratch-1/ww220/postgresql-7.1.3/lib testlibpq.c   -o testlibpq 
>
> You need a -lpq in there somewhere.
>
> > Afte searching on the net, I added -lpq but the result is not positive:
> >
> > gcc -O2 -Wall -Wmissing-prototypes -Wmissing-declarations -I../../../src/interfaces/libpq -I../../../src/include
testlibpq.c  -o testlibpq -lpq 
> > testlibpq.c: In function `exit_nicely':
> > testlibpq.c:14: warning: implicit declaration of function `exit'
> > /usr/bin/ld: cannot find -lpq
> > collect2: ld returned 1 exit status
>
> Did you install it? Look around for a file named libpq.so. Add an option
> -L/directory/containing/that/lib after the -I options.
>
> HTH,
> --
> Martijn van Oosterhout   <kleptog@svana.org>   http://svana.org/kleptog/
> > Canada, Mexico, and Australia form the Axis of Nations That
> > Are Actually Quite Nice But Secretly Have Nasty Thoughts About America
>
> ---------------------------(end of broadcast)---------------------------
> TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org
>

Re: erros when making examples in /src/test/examples

From
Martijn van Oosterhout
Date:
On Thu, May 30, 2002 at 01:53:19PM +0100, Wei Wang wrote:
> Thanks a lot.
>
>
> It works:
>
> gcc -O2 -Wall -Wmissing-prototypes -Wmissing-declarations -I../../../src/interfaces/libpq -I../../../src/include
-Wl,-rpath,/local/scratch-1/ww220/postgresql-7.1.3/lib -L/homes/ww220/myspace/postgresql-7.1.3/lib testlibpq.c   -o
testlibpq-lpq 
> testlibpq.c: In function `exit_nicely':
> testlibpq.c:14: warning: implicit declaration of function `exit'
>
> I am a total newbie to almost everything. I put
> export PATH=/local/scratch-1/ww220/myspace/postgresql-7.1.3/lib:$PATH
> in .bash_profile and did ". .bash_profile". Is that different from putting
> -L switch in gcc command?

The PATH variable list directories to look for *programs*. So that's
different. -L tells the compiler where to look for libraries while linking.
And if you add that directory to /etc/ld.so.conf (if supported by your
dynamic linker) then you don't need the -rpath bit either.

--
Martijn van Oosterhout   <kleptog@svana.org>   http://svana.org/kleptog/
> Canada, Mexico, and Australia form the Axis of Nations That
> Are Actually Quite Nice But Secretly Have Nasty Thoughts About America

Re: erros when making examples in /src/test/examples

From
Wei Wang
Date:
Great thanks.

But if I am not root, hence no access to /etc/ld.so.conf, where should I specify such libraries for the programs to
lookfor? 

Wei

On Thu, 30 May 2002 23:42:48 +1000
Martijn van Oosterhout <kleptog@svana.org> wrote:

> On Thu, May 30, 2002 at 01:53:19PM +0100, Wei Wang wrote:
> > Thanks a lot.
> >
> >
> > It works:
> >
> > gcc -O2 -Wall -Wmissing-prototypes -Wmissing-declarations -I../../../src/interfaces/libpq -I../../../src/include
-Wl,-rpath,/local/scratch-1/ww220/postgresql-7.1.3/lib -L/homes/ww220/myspace/postgresql-7.1.3/lib testlibpq.c   -o
testlibpq-lpq 
> > testlibpq.c: In function `exit_nicely':
> > testlibpq.c:14: warning: implicit declaration of function `exit'
> >
> > I am a total newbie to almost everything. I put
> > export PATH=/local/scratch-1/ww220/myspace/postgresql-7.1.3/lib:$PATH
> > in .bash_profile and did ". .bash_profile". Is that different from putting
> > -L switch in gcc command?
>
> The PATH variable list directories to look for *programs*. So that's
> different. -L tells the compiler where to look for libraries while linking.
> And if you add that directory to /etc/ld.so.conf (if supported by your
> dynamic linker) then you don't need the -rpath bit either.
>
> --
> Martijn van Oosterhout   <kleptog@svana.org>   http://svana.org/kleptog/
> > Canada, Mexico, and Australia form the Axis of Nations That
> > Are Actually Quite Nice But Secretly Have Nasty Thoughts About America
>

Re: erros when making examples in /src/test/examples

From
Bill Gribble
Date:
On Thu, 2002-05-30 at 11:14, Wei Wang wrote:
> But if I am not root, hence no access to /etc/ld.so.conf, where should
> I specify such libraries for the programs to look for?

This is actually a very hard problem to solve in general.

You can control the behavior of the runtime dynamic linker with
environment variables: LD_LIBRARY_PATH to add to the search path for
libraries linked in with gcc, LTDL_LIBRARY_PATH for libraries linked at
runtime via ltdl_open().

If there's a possibility that there will be multiple versions of a
library installed on the target system, or the libs are installed in
non-system locations (outside /lib and /usr/lib) you may need to make
special provisions to make sure your program will run for all users. I
think it's ideal to make it so that as long as a program is in your PATH
it will run without requiring the user to set LD_LIBRARY_PATH and
friends.

My development team uses an overrides mechanism that always forces the
environment of the running program to match up with what was discovered
by the 'configure' process at build time, and policy dictates that we
use pkg-config in such a way that libraries can query other libraries at
build time about where they are installed and for the settings of any
relevant environment variables.

b.g.



Re: erros when making examples in /src/test/examples

From
"McCaffity, Ray (Contractor)"
Date:
I already sent a reply to Wei, but all you really have to do is make sure
it's in your path.  Usually most users will have a .profile or .login or
.bashrc,
.kshrc, .cshrc  etc...
just add this to your env variables.
LD_LIBRARY_PATH=/path/to/wherever:/usr/local/lib:/usr/local/pgsql/lib  ...
and so on ...
If necessary, do the same for the user that postgresql is running as.
Finally, in your compile, I noticed this works with apache, php, and
postgresql..
--includedir=/path/to/wherever/lib
Some linux system let any user run ld.config (a bad idea IMHO, but..)
For Solaris, almost any user can chnage his library path by using crle.

Ray


-----Original Message-----
From: Bill Gribble [mailto:grib@linuxdevel.com]
Sent: Thursday, May 30, 2002 9:54 AM
To: Wei Wang
Cc: Martijn van Oosterhout; pgsql-general@postgresql.org
Subject: Re: [GENERAL] erros when making examples in /src/test/examples


On Thu, 2002-05-30 at 11:14, Wei Wang wrote:
> But if I am not root, hence no access to /etc/ld.so.conf, where should
> I specify such libraries for the programs to look for?

This is actually a very hard problem to solve in general.

You can control the behavior of the runtime dynamic linker with
environment variables: LD_LIBRARY_PATH to add to the search path for
libraries linked in with gcc, LTDL_LIBRARY_PATH for libraries linked at
runtime via ltdl_open().

If there's a possibility that there will be multiple versions of a
library installed on the target system, or the libs are installed in
non-system locations (outside /lib and /usr/lib) you may need to make
special provisions to make sure your program will run for all users. I
think it's ideal to make it so that as long as a program is in your PATH
it will run without requiring the user to set LD_LIBRARY_PATH and
friends.

My development team uses an overrides mechanism that always forces the
environment of the running program to match up with what was discovered
by the 'configure' process at build time, and policy dictates that we
use pkg-config in such a way that libraries can query other libraries at
build time about where they are installed and for the settings of any
relevant environment variables.

b.g.



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

http://www.postgresql.org/users-lounge/docs/faq.html

Re: erros when making examples in /src/test/examples

From
Bill Gribble
Date:
On Thu, 2002-05-30 at 12:01, McCaffity, Ray (Contractor) wrote:
> Usually most users will have a .profile or .login or
> .bashrc, .kshrc, .cshrc  etc... just add this to your env variables.
> LD_LIBRARY_PATH=/path/to/wherever:/usr/local/lib:/usr/local/pgsql/lib  ...
> and so on ...

Well, this "works" in the sense that if all your users get the values
right it will DTRT.  However, it's my experience that requiring manual
setting of LD_LIBRARY_PATH is a recipe for generating a million bug
reports like "the application crashed and I don't know why".

Often there are multiple versions of particular libraries laying around
on the system, especially common-but-not-standard things like the
postgres libraries, and doubly especially on multiuser systems in
semi-public places like universities, which can have dozens of different
publically accessible lib directories.  Many times, slightly
incompatible versions of the libraries won't have their version numbers
bumped properly, or won't be configure-tested properly, and you can end
up with a very surprising selection of libraries from all over the
system linked in to your app.  Sometimes they'll work together ... other
times not.

It's the application's problem to make sure the correct libraries get
linked at runtime, IMO; the knowledgeable user should be able to
override the app defaults, but the default should be to work in a way
that at least is predictable.

b.g.