gcc linking with shared library

N

Nick Birnie

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)
 
J

James Kanze

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.)
 
N

Nick Birnie

James said:
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
 

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

Forum statistics

Threads
473,795
Messages
2,569,644
Members
45,357
Latest member
RuthEsteve

Latest Threads

Top