gcc linking with shared library

Discussion in 'C++' started by Nick Birnie, Apr 12, 2009.

  1. Nick Birnie

    Nick Birnie Guest

    Hi,

    I am developing a shared library and have a question about linking some
    code with it.

    Once I have a shared object compiled, with the .so still in the source
    tree, I want to compile and link some tests with it, without first
    installing the library.

    If I compile the tests with the -L. and -lname switches, gcc produces
    the object code, but the library is not found at run time.

    Any idea what the problem could be?

    Many thanks,

    Nick

    P.S.

    This is the error:

    ../test: error while loading shared libraries: libnbthread.so: cannot
    open shared object file: No such file or directory

    Output of ldd:

    linux-gate.so.1 => (0x00110000)
    libnbthread.so => not found
    libc.so.6 => /lib/libc.so.6 (0x006f4000)
    /lib/ld-linux.so.2 (0x006cf000)
    Nick Birnie, Apr 12, 2009
    #1
    1. Advertising

  2. Nick Birnie

    James Kanze Guest

    On Apr 12, 5:37 am, Nick Birnie <> wrote:

    > I am developing a shared library and have a question about
    > linking some code with it.


    > Once I have a shared object compiled, with the .so still in
    > the source tree, I want to compile and link some tests with
    > it, without first installing the library.


    > If I compile the tests with the -L. and -lname switches, gcc
    > produces the object code, but the library is not found at run
    > time.


    > Any idea what the problem could be?


    This is very platform dependent, so you really should ask in
    comp.unix.programmer, but under Posix (which I suppose because
    of the .so extension), dynamic libraries are searched in the
    directories in $LD_LIBRARY_PATH. I use something like the
    following in my makefiles:

    runtest : $(testDependencies)
    LD_LIBRARY_PATH=..:$$LD_LIBRARY_PATH ; \
    export LD_LIBRARY_PATH ; \
    $(testProgram)

    (I actually use something a lot more complex, since it works
    under both Windows and Unix, and it takes into account different
    options, which modify where the actual test programs reside.)

    --
    James Kanze (GABI Software) email:
    Conseils en informatique orientée objet/
    Beratung in objektorientierter Datenverarbeitung
    9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
    James Kanze, Apr 12, 2009
    #2
    1. Advertising

  3. Nick Birnie

    Nick Birnie Guest

    James Kanze wrote:
    > On Apr 12, 5:37 am, Nick Birnie <> wrote:
    >
    >> I am developing a shared library and have a question about
    >> linking some code with it.

    >
    >> Once I have a shared object compiled, with the .so still in
    >> the source tree, I want to compile and link some tests with
    >> it, without first installing the library.

    >
    >> If I compile the tests with the -L. and -lname switches, gcc
    >> produces the object code, but the library is not found at run
    >> time.

    >
    >> Any idea what the problem could be?

    >
    > This is very platform dependent, so you really should ask in
    > comp.unix.programmer, but under Posix (which I suppose because
    > of the .so extension), dynamic libraries are searched in the
    > directories in $LD_LIBRARY_PATH. I use something like the
    > following in my makefiles:
    >
    > runtest : $(testDependencies)
    > LD_LIBRARY_PATH=..:$$LD_LIBRARY_PATH ; \
    > export LD_LIBRARY_PATH ; \
    > $(testProgram)
    >
    > (I actually use something a lot more complex, since it works
    > under both Windows and Unix, and it takes into account different
    > options, which modify where the actual test programs reside.)
    >


    Hi there,

    Thanks very much for your reply. Indeed an env export was required. I
    assigned a variable in my makefile to export LD_LIBRARY_PATH..... that
    is dereferenced as required.

    Many thanks for your help,

    Nick
    Nick Birnie, Apr 12, 2009
    #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. Albert
    Replies:
    4
    Views:
    512
    Mike Wahler
    Sep 29, 2003
  2. Lior Sapir
    Replies:
    1
    Views:
    574
    Victor Bazarov
    Mar 31, 2005
  3. Visa Inquirer
    Replies:
    5
    Views:
    357
    Walter Roberson
    Apr 11, 2008
  4. nutzzz
    Replies:
    1
    Views:
    4,434
    nutzzz
    Sep 30, 2008
  5. Replies:
    1
    Views:
    102
Loading...

Share This Page