Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > question about linux static libraries

Reply
Thread Tools

question about linux static libraries

 
 
Brano
Guest
Posts: n/a
 
      03-15-2006
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.



 
Reply With Quote
 
 
 
 
Vladimir S. Oka
Guest
Posts: n/a
 
      03-15-2006

Brano wrote:
> 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.

--
BR, Vladimir

 
Reply With Quote
 
 
 
 
Igmar Palsenberg
Guest
Posts: n/a
 
      03-20-2006
Brano wrote:

> ... 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
standard libraries don't behave like standard 'libraries' Sriram Srinivasan Python 13 11-12-2009 06:05 PM
Question about static libraries exporting functions moschops C++ 5 02-10-2008 12:30 AM
Using mandatory libraries (custom class loading vs. expanding libraries) Karsten Wutzke Java 21 06-29-2007 09:25 PM
how to link static library to another static libraries free2cric@yahoo.com C++ 2 05-16-2005 04:40 PM
Linking with Static Libraries (linux) Herr Fieldmarshall C++ 4 01-28-2005 02:14 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57