Обсуждение: errors when making examples in /src/test/examples
Hi, I am just trying to make the frontend programs in /src/test/examples There seems to be some problem with finding the libpq libraries. 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
Wei Wang wrote: > Hi, > > 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? You need to tell gcc where to find libpq.so. You do that with the -L option. So find libpq.so (I don't know where it is in the compile tree) and then add -L/path/to/libpq to the command. So you might end up with something like: gcc -I../../../src/interfaces/libpq -I../../../src/include -L../../../src/lib testlibpq.c -o testlibpq -lpq Again, I don't really know where libpq.so is, so find it and substitute the real path for the one above. --Jeremy
Thanks. Yes, it works. I got rid of the -Wl and -rpath and it still works fine. Can I include this anywhere in .bash_profile so that I don't have to include this library path everytime I compile? On Thu, 30 May 2002 07:28:42 -0700 Jeremy Buchmann <jeremy@wellsgaming.com> wrote: > Wei Wang wrote: > > Hi, > > > > 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? > > You need to tell gcc where to find libpq.so. You do that with the -L > option. So find libpq.so (I don't know where it is in the compile tree) > and then add -L/path/to/libpq to the command. > > So you might end up with something like: > > gcc -I../../../src/interfaces/libpq -I../../../src/include > -L../../../src/lib testlibpq.c -o testlibpq -lpq > > Again, I don't really know where libpq.so is, so find it and substitute > the real path for the one above. > > --Jeremy > > > > >