Subject: Re: Wait, isn't rpath supposed to be set automagically?

From: Stefano Lattarini <[email-masked]>
Date: Sun, 26 Feb 2012 16:10:54 +0100

On 02/26/2012 03:47 PM, Miles Bader wrote:
> I thought that as long as one used ".la" libraries, automake+libtool
> was supposed to handle all the grotty stuff like rpath automatically,
> adding -rpath $(libdir) if you depend on libraries installed to libdir
> and libdir isn't on the system library search path.  [Yeah, I also
> know some people hate rpath, but ...]
> 
> But ... it doesn't seem to.  Is something broken, is there an option I
> should set... or?
> 
> [I guess I can add "-rpath <blahblaha>" somewhere in Makefile.am, but
> I don't really want to add system-dependent stuff that libtool's
> supposed to be handling; isn't that why libtool exists in the first
> place?]
> 
> automake version 1.11.3, libtool version 2.4.2
> 
> Thanks,
> 
> -Miles
> 
> 
> Example:
> 
> configure.ac:
>         AC_INIT([blah], [0.1], [bob])
>         AM_INIT_AUTOMAKE([foreign])
>         LT_INIT
>         AC_PROG_CC
>         AC_CONFIG_FILES([Makefile])
>         AC_OUTPUT
> Makefile.am:
>         bin_PROGRAMS = blah
>         lib_LTLIBRARIES = liboink.la
>         blah_SOURCES = blah.c
>         blah_LDADD = liboink.la
>         liboink_la_SOURCES = oink.c
> blah.c:
>         extern void oink ();
>         int main () { oink (); }
> oink.c:
>         void oink () { }
> 
> Commands:
>         $ autoreconf --install
>                 ...
>         $ ./configure
>                 ...
>         $ make
>                 ...
>         $ sudo make install
>                 ...
>         $ /usr/local/bin/blah
>         /usr/local/bin/blah: error while loading shared libraries: liboink.so.0: cannot open shared object file: No such file or directory
>         $ LD_LIBRARY_PATH=/usr/local/lib /usr/local/lib/blah
>         $ ldd /usr/local/bin/blah
>                 linux-vdso.so.1 =>  (0x00007fff247c5000)
>                 liboink.so.0 => not found
>                 libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f5ceeb26000)
>                 /lib64/ld-linux-x86-64.so.2 (0x00007f5ceeed1000)
>         $ readelf -d /usr/local/bin/blah | grep RPATH
>         $ 
> 
I must admit I know very little of the Automake's libtool support, so I'm
not sure whether this is a bug or not; still, the automake documentation
reads somewhere:

  For libraries whose destination directory is known when Automake runs,
  Automake will automatically supply the appropriate -rpath option to
  libtool. This is the case for libraries listed explicitly in some
  installable _LTLIBRARIES variables such as lib_LTLIBRARIES.

so we have *at least* a documentation issue.  I should look at this more
carefully (probably after the 1.12 release); for now, I'm opening a report
in the bug tracker so that we won't forget about the issue.

Thanks,
  Stefano