Cannot Statically Link libpq.a

Поиск
Список
Период
Сортировка
Искать

Cannot Statically Link libpq.a

От:
Emilio Recio <erecio@storm.jmc.tju.edu>
Дата:
(sorry if you get this twice, but the email kept getting 'deffered' 
because of a bad hello or something last night)

I try to statically link the testpq.c program via:

gcc -o testpq -lpq -static testpq.c

and get the following error:
[erecio@moz postgres]$ gcc -o testpq -static -lpq testpq.c
/tmp/ccIp5I09.o: In function `exit_nicely':
/tmp/ccIp5I09.o(.text+0xd): undefined reference to `PQfinish'
/tmp/ccIp5I09.o: In function `main':
/tmp/ccIp5I09.o(.text+0x60): undefined reference to `PQsetdbLogin'
/tmp/ccIp5I09.o(.text+0x73): undefined reference to `PQstatus'
/tmp/ccIp5I09.o(.text+0xa4): undefined reference to `PQerrorMessage'

/tmp/ccIp5I09.o(.text+0x35d): undefined reference to `PQfinish'
collect2: ld returned 1 exit status

While dynamically linking it works fine:

$ gcc -o testpq -lpq testpq.c
$ ldd testpq         libpq.so.2 => /usr/lib/libpq.so.2 (0x4002c000)         libc.so.6 => /lib/i686/libc.so.6 (0x42000000)         libssl.so.2 => /lib/libssl.so.2 (0x4003f000)         libcrypto.so.2 => /lib/libcrypto.so.2 (0x4006c000)         libkrb5.so.3 => /usr/kerberos/lib/libkrb5.so.3 (0x40130000)         libk5crypto.so.3 => /usr/kerberos/lib/libk5crypto.so.3 
(0x40187000)         libcom_err.so.3 => /usr/kerberos/lib/libcom_err.so.3 (0x40197000)         libcrypt.so.1 => /lib/libcrypt.so.1 (0x4019a000)         libresolv.so.2 => /lib/libresolv.so.2 (0x401c7000)         libnsl.so.1 => /lib/libnsl.so.1 (0x401d8000)         /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000)         libdl.so.2 => /lib/libdl.so.2 (0x401ed000)

libpq.a is in /usr/lib, but it's only about 93k. For the object files
that seems alot. I need to statically link the library because I am
going to be using a custom program in an embedded device where none of
the above libraries mentioned in the ldd works. All the the programs
statically link fine, except for libpq. I am using the redhat 7.3 rpms.

-Elmo




Re: Cannot Statically Link libpq.a

От:
Emilio Recio <erecio@storm.jmc.tju.edu>
Дата:
Emilio Recio wrote:

> libpq.a is in /usr/lib, but it's only about 93k. For the object files
> that seems alot. I need to statically link the library because I am
> going to be using a custom program in an embedded device where none of
> the above libraries mentioned in the ldd works. All the the programs
> statically link fine, except for libpq. I am using the redhat 7.3 rpms.

-- New

Several points to follow up on: ./configure && make && make install on 
slackware 8.1 also did not produce a libpq.a file which I can use for 
static linking. Tried (from postgresql src dir):

-- Cmd Line
ar r libpq.a `find /usr/local/src/postgresql-7.2.2/src |grep -v main.o`
ranlib libpq.a

-- 
And no go... can anyone tell me how to create a static library? Or which 
object files to copy from postgresql source code to be able to link them 
with testpg.c (note testpg.c can be found in the documentation for 
postgresql - my program is significantly smaller and uses less postgress 
calls.)

-- Clarification

ALso above, i meant, libpq.a seemed like too little, but it was 3am :)

-Elmo


Re: Cannot Statically Link libpq.a

От:
Emilio Recio <erecio@storm.jmc.tju.edu>
Дата:
Patrick Welche wrote:
> Very long shot: what if you move the -lpq to the end?
> 
> gcc -o testpq -static testpq.c -lpq

YOU ROCK!

erecio@datacollector1:$ make
gcc -static -o testpg -L. testpg.o -lpq
./libpq.a(fe-auth.o): In function `pg_password_sendauth':
fe-auth.o(.text+0x148): undefined reference to `crypt'
collect2: ld returned 1 exit status
make: *** [pgconn] Error 1

-- after editing the makefile

$ make
gcc -static -o testpg -L. testpg.o -lpq -lcrypt
strip testpg && size testpg   text    data     bss     dec     hex filename 437341   11488  165800  614629   960e5 pgconn

$ ldd testpg        not a dynamic executable

I've been away from C for too long... QT has pampered me and PHP has 
made me lazy. Java well... has made me take everything for granted. :) 
Hopefully this list is archived so someone else doesn't make that same 
'oops'. Thanks a lot.

~Elmo


FAQ