question about linux static libraries

B

Brano

Hello guys, sorry for the really dumb question, but I'm just beginner in
linux programming. I have the following code in test.c:

#include <stdio.h>
#include <libpq-fe.h>

int main() {
int do_init = 1;
PQinitSSL(do_init);
}

.... so I just want to call one function from postgres library. According
to the nm command (nm /usr/lib/libpq.a) the object (which contains
PQinitSSL() function contains also number of SSL functions e.g. BIO_free,
BIO_new_mem_buf etc. When I'm trying to compile test program with command:

gcc -o test test.c -lpq

everything is OK, but when I'm trying to compile the same code with the
libpq library in the local directory, I've got a lot of undefined
reference messages on SSL functions

cp /usr/lib/libpq.a .
gcc -o test test.c -L. -lpq

So, how it is possible, that the first command works fine and the
second not ? I'm trying to compile it with the same library in both
cases. I know, that libpq.a library does not contains libcrypto.a
library. Are in the libpq.a (and generally any other) library references
to the other libraries ? And how can I determine those references ? Is it
possible with nm command ? Many thanks for the help.
 
V

Vladimir S. Oka

Brano said:
Hello guys, sorry for the really dumb question, but I'm just beginner in
linux programming. I have the following code in test.c:

And what prompted you to ask here? Your question has nothing to do with
C, and everything to do with your tools and possibly OS. You stand a
chance of getting an answer in groups dedicated to Linux and/or GCC.
Here, only Standard C is discussed. Have a look at
<http://www.clc-wiki.net/wiki/Introduction_to_comp.lang.c> before
posting again.
 
I

Igmar Palsenberg

Brano said:
... so I just want to call one function from postgres library. According
to the nm command (nm /usr/lib/libpq.a) the object (which contains
PQinitSSL() function contains also number of SSL functions e.g. BIO_free,
BIO_new_mem_buf etc. When I'm trying to compile test program with command:

libpq.a contains references to those functions, not the functions.
gcc -o test test.c -lpq

This probably links agains the .so, not the static lib (hint : ldd binary)
everything is OK, but when I'm trying to compile the same code with the
libpq library in the local directory, I've got a lot of undefined
reference messages on SSL functions

cp /usr/lib/libpq.a .
gcc -o test test.c -L. -lpq

So, how it is possible, that the first command works fine and the
second not ?

Because the first one uses the .so (which also contains the
dependencies), while the second one uses the .a, which only contains
references to the SSL functions, not where to get them.

I'm trying to compile it with the same library in both
cases. I know, that libpq.a library does not contains libcrypto.a
library. Are in the libpq.a (and generally any other) library references
to the other libraries ? And how can I determine those references ? Is it
possible with nm command ? Many thanks for the help.

See the nm manual for that. The U symbol type is most interesting in
this case.


Igmar
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top