question about linux static libraries

Discussion in 'C Programming' started by Brano, Mar 15, 2006.

  1. Brano

    Brano Guest

    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.
     
    Brano, Mar 15, 2006
    #1
    1. Advertising

  2. 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
     
    Vladimir S. Oka, Mar 15, 2006
    #2
    1. Advertising

  3. 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
     
    Igmar Palsenberg, Mar 20, 2006
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Herr Fieldmarshall

    Linking with Static Libraries (linux)

    Herr Fieldmarshall, Jan 28, 2005, in forum: C++
    Replies:
    4
    Views:
    1,128
    Lionel B
    Jan 28, 2005
  2. Replies:
    2
    Views:
    6,543
    Maett
    May 16, 2005
  3. Karsten Wutzke
    Replies:
    21
    Views:
    934
    Roedy Green
    Jun 29, 2007
  4. moschops
    Replies:
    5
    Views:
    432
    Jeff Schwab
    Feb 10, 2008
  5. Sriram Srinivasan
    Replies:
    13
    Views:
    583
    Benjamin Kaplan
    Nov 12, 2009
Loading...

Share This Page