mkogg.py: Fix 'self.get_mp4_metadata(self, source)'
[blog.git] / posts / rpath.mdwn
index f78b7aa9a93cd2804ce5d13926593fe463320495..112b16517ae7fd585d2912406b4d5f1c7fcca27a 100644 (file)
@@ -56,6 +56,49 @@ case of installing a library *into* the standard library path,
 Along the way, I ran across two other interesting posts by Diego
 Pettenò about not [bundling][] [libraries][].
 
+Setting `RPATH` and `RUNPATH`
+-----------------------------
+
+Most of the time, you'll want to avoid setting `RPATH` and `RUNPATH`
+and just use libraries in your usual linking path.  However, sometimes
+they are useful.  For example, [[SimulAVR]] depends on the
+AVR-specific `libbfd`, which is hopefully not in your usual path.  On
+Gentoo, [[crossdev|AVR]] installs under `/usr/lib/binutils/`:
+
+    $ binutils-config -c avr
+    avr-git
+    $ grep PATH /etc/env.d/binutils/avr-git 
+    LIBPATH="/usr/lib/binutils/avr/git"
+
+When you link against this library, you'll want to set `RUNPATH` so
+you don't have to remember to use `LD_LIBRARY_PATH` every time you run
+`simulavr`.  Of course, if you switch to a different binutils version
+(e.g. not `git`), you'll need to fix the `RUNPATH` to point to the new
+target (or just rebuild `simulavr` against the new version).
+
+Since you're probably not calling the linker directly when you build
+`simulavr`, you'll want to set some linker flags at configure time:
+
+    $ LDFLAGS=-Wl,-rpath=/usr/lib/binutils/avr/git,--enable-new-dtags ./configure …
+
+The relevant linker flags are `-rpath` and `--enable-new-dtags`.
+Without `--enable-new-dtags`, you'll just set the `RPATH` flag, which
+is probably not what you want.  With `--enable-new-dtags`, you'll set
+both `RPAH` and `RUNPATH` to the same value.  From `ld(1)`:
+
+> The `DT_RPATH` entries are ignored if `DT_RUNPATH` entries exist.
+
+so setting both is the same as just setting `RUNPATH` (except for
+tools like `chrpath` which are only designed to handle a single tag).
+You can use [readelf][] to see if the tags were set:
+
+    $ readelf --dynamic /usr/bin/simulavr | grep PATH
+     0x000000000000000f (RPATH)    Library rpath: [/usr/lib/binutils/avr/git]
+     0x000000000000001d (RUNPATH)  Library runpath: [/usr/lib/binutils/avr/git]
+
+On Gentoo, `--enable-new-dtags` has been [the default since
+2005][default], but explicitly including the flag can't hurt ;).
+
 [wiki]: http://wiki.debian.org/RpathIssue
 [list]: http://www.mail-archive.com/debian-devel@lists.debian.org/msg61772.html
 [c1]: http://www.mail-archive.com/debian-devel@lists.debian.org/msg61787.html
@@ -68,5 +111,7 @@ Pettenò about not [bundling][] [libraries][].
 [ELF]: http://en.wikipedia.org/wiki/Executable_and_Linkable_Format
 [bundling]: http://blog.flameeyes.eu/2009/01/02/bundling-libraries-for-despair-and-insecurity
 [libraries]: http://blog.flameeyes.eu/2009/03/23/bundling-libraries-the-curse-of-the-ancients
+[readelf]: http://www.gnu.org/software/binutils/
+[default]: http://comments.gmane.org/gmane.comp.gnu.binutils/57379
 
 [[!tag tags/linux]]