Using shared lib in local dir?

Using shared lib in local dir?

Post by fantast.. » Sat, 19 Jun 1999 04:00:00



Linux newbie, perhaps a simple question but I haven't been
able to find an answer on dejanews or in the faqs.

I have a bunch of code shared by several related applications.
I built a shared library, and placed in the same directory as
the applications. When I try to run an application, I get an
message that the library can't be found. Is there some way to
get the applications to use the library without having to use
dlopen and dlsym on all the symbols (there's a lot of them)?
In Win32, this is analogous to placing a .DLL file in the same
directory as the executable, when the executable runs, it
first looks in the local directory for the library, before
checking the path. Since this library is only used by my own
applications, and really has no use to anyone else, I'd don't
want to put it in a shared space like /usr/local/lib or the
like. I see that Quake3 does this, are they dynamically loading
the library? Seems like a PITA. Alright, enough rambling.

Jason

Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.

 
 
 

Using shared lib in local dir?

Post by Michael Davi » Sat, 19 Jun 1999 04:00:00



>Linux newbie, perhaps a simple question but I haven't been
>able to find an answer on dejanews or in the faqs.

>I have a bunch of code shared by several related applications.
>I built a shared library, and placed in the same directory as
>the applications. When I try to run an application, I get an
>message that the library can't be found. Is there some way to
>get the applications to use the library without having to use
>dlopen and dlsym on all the symbols (there's a lot of them)?
>In Win32, this is analogous to placing a .DLL file in the same
>directory as the executable, when the executable runs, it
>first looks in the local directory for the library, before
>checking the path. Since this library is only used by my own
>applications, and really has no use to anyone else, I'd don't
>want to put it in a shared space like /usr/local/lib or the
>like. I see that Quake3 does this, are they dynamically loading
>the library? Seems like a PITA. Alright, enough rambling.

>Jason

I'm on a Sun box right now, but I think this also works for Linux:
There is an environment variable called LD_LIBRARY_PATH which
the ld library uses to find the libraries. So you can do:
export LD_LIBRARY_PATH=.:$LD_LIBRARY_PATH
to prepend the current directory.

Or you can call dlopen like so:
void * dlhandle = dlopen( "./libMyLib.so", RTLD_LAZY );
I haven't tried that, but the man page for dlopen implies
that that will work.

--
// Michael Davis -- Solaris code slave and happy Linux User.
//
// From sunny Toronto...

 
 
 

Using shared lib in local dir?

Post by Paul Kimo » Sun, 20 Jun 1999 04:00:00



> I have a bunch of code shared by several related applications.
> I built a shared library, and placed in the same directory as
> the applications. When I try to run an application, I get an
> message that the library can't be found. Is there some way to
> get the applications to use the library without having to use
> dlopen and dlsym on all the symbols (there's a lot of them)?

IF YOU WILL NEVER CHANGE THE LIBRARY'S PATH (such as by moving
it to another machine), you can hard-code a library search
location using the "-rpath" option when linking.  See the "ld"
info pages.

--

 
 
 

Using shared lib in local dir?

Post by John Burto » Sun, 20 Jun 1999 04:00:00



>Linux newbie, perhaps a simple question but I haven't been
>able to find an answer on dejanews or in the faqs.

>I have a bunch of code shared by several related applications.
>I built a shared library, and placed in the same directory as
>the applications. When I try to run an application, I get an
>message that the library can't be found. Is there some way to
>get the applications to use the library without having to use
>dlopen and dlsym on all the symbols (there's a lot of them)?
>In Win32, this is analogous to placing a .DLL file in the same
>directory as the executable, when the executable runs, it
>first looks in the local directory for the library, before
>checking the path. Since this library is only used by my own
>applications, and really has no use to anyone else, I'd don't
>want to put it in a shared space like /usr/local/lib or the
>like. I see that Quake3 does this, are they dynamically loading
>the library? Seems like a PITA. Alright, enough rambling.

If you link with your shared library using "./libname.so" rather than just
"libname.so"
it will use the path and work. I don't know if this is documented beheivour
or
just luck.
 
 
 

Using shared lib in local dir?

Post by fantast.. » Tue, 22 Jun 1999 04:00:00


Quote:> IF YOU WILL NEVER CHANGE THE LIBRARY'S PATH (such as by moving
> it to another machine), you can hard-code a library search
> location using the "-rpath" option when linking.  See the "ld"
> info pages.

Adding the linker flag "-rpath ." did the job perfectly, it's
working great now, thanks for the tip.

Jason

Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.