Linking a third-party library with my own library
Rodrigo Dominguez
roddomi@hotmail.com
Tue Mar 10 02:53:00 GMT 2009
Hi Axel,
> -----Original Message-----
> From: Axel Freyn [mailto:axel-freyn@gmx.de]
> Sent: Sunday, March 08, 2009 2:28 PM
> To: gcc-help@gcc.gnu.org
> Subject: Re: Linking a third-party library with my own library
>
> Hi Rodrigo,
> On Sun, Mar 08, 2009 at 02:04:54PM -0400, Rodrigo Dominguez wrote:
> > g++ -shared [other switches] -L/path-to-libpapi [more switches] -
> lpapi -o
> > mylibrary.so mylibrary.o
> > The command executes without errors. However, when I run 'ldd
> mylibrary.o' I
> > get:
> > libpapi.so.3 => not found
> >
> > I can see that libpapi.so.3 exists under /path-to-libpapi. Needless
> to say,
> > when I try to load my library it complains about not being able to
> find
> > libpapi.so.3.
> >
> > What am I missing?
>
> The compiler did its work correctly, however, as you use static
> linkage,
> you have to tell "ldd" where to look for the library libpapi.so.3:
> Either you can do it system-wide by changing /etc/ld.so.conf (on
> linux), or by defining the environment-variable LD_LIBRARY_PATH
> e.g. in bash,
>
> LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/path-to-libpapi ldd mylibrary.o
>
> should work (You could also use LD_LIBRARY_PATH=/path-to-libpapi,
> however I repeated the $LD_LIBRARY_PATH for the case that this variable
> had already been defined...)
>
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):
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)?
>
> HTH,
>
> Axel
Thanks for your help,
Rodrigo
More information about the Gcc-help
mailing list