Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > gcc linking with shared library

Reply
Thread Tools

gcc linking with shared library

 
 
Nick Birnie
Guest
Posts: n/a
 
      04-12-2009
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)

 
Reply With Quote
 
 
 
 
James Kanze
Guest
Posts: n/a
 
      04-12-2009
On Apr 12, 5:37 am, Nick Birnie <(E-Mail Removed)> 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:(E-Mail Removed)
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
 
Reply With Quote
 
 
 
 
Nick Birnie
Guest
Posts: n/a
 
      04-12-2009
James Kanze wrote:
> On Apr 12, 5:37 am, Nick Birnie <(E-Mail Removed)> 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
 
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
Linking shared lib with GCC - undefined symbol nutzzz C++ 1 09-30-2008 12:54 PM
Linking with a particular shared library by full path overridingLD_LIBRARY_PATH Visa Inquirer C Programming 5 04-10-2008 11:02 PM
problems with linking a dynamic shared library using kdevelop 2.1 and linux fedora(1) Lior Sapir C++ 1 03-30-2005 11:39 PM
Q: can't find C++ symbols if gcc linking with Sun C++ library Albert C++ 4 09-29-2003 04:03 PM
AIX + GCC 2.95.3 - Python (2.1 or 2.2) - building the shared library(.so) for python - HOW TO?!? hab Python 2 07-07-2003 04:35 PM



Advertisments