Linking a third-party library with my own library

Axel Freyn axel-freyn@gmx.de
Tue Mar 10 09:25:00 GMT 2009


Hi Rodrigo,
On Mon, Mar 09, 2009 at 10:53:08PM -0400, Rodrigo Dominguez wrote:
>  [...]
> LD_LIBRARY_PATH works as you mentioned. Is this error happening because I am
> using
> static linkage (-lpapi)? I tried using dynamic linkage (libpapi.so):
Sorry, it was a typing mistake from me - you using dynamic linkage (I
wanted to say "not using static linkage", but omitted "not"...)
> 
> g++ -shared [other switches] -o mylibrary.so mylibrary.o
> /path-to-libpapi/libpapi.so
> 
> but I get the same problem. Is this the right way to do dynamic linkage? Is
> there a 
> way to make it work without having to set LD_LIBRARY_PATH (or
> /etc/ld.so.conf)?
As far as I know, there is no other way. As the idea behind dynamic
linkage is, that the code links the library files at runtime, no
pathes to the libraries are integrated into compiled code (otherwise, it
would be impossible to transfer a compiled library to another machine
where the libraries are stored in another directory...).

My solution to this problem is usually:
 - for libraries, which I use very often:
   * on machines where I'm root: changing ld.so.conf
   * on machines where I'm only user: redefining LD_LIBRARY_PATH in my .profile.
 - for rarely-used libraries: I start the program not directly from
   command line, but using a shell script which defines LD_LIBRARY_PATH
   accordingly

HTH,

Axel



More information about the Gcc-help mailing list