[Tutor] Set LD_LIBRARY_PATH and equivalents platform-independently

eryksun eryksun at gmail.com
Fri Jan 18 04:07:56 CET 2013


On Thu, Jan 17, 2013 at 10:33 AM, Albert-Jan Roskam <fomcl at yahoo.com> wrote:
>
> The goal is to load the C libraries (dll, so, dylib, etc) that my program
> needs.
>
> Anyway, I looked up your two suggestions about library_dirs and
> runtime_library_dirs. What is meant by "at link time"?

library_dirs adds search paths for the linker (e.g. ld) for finding
shared libraries (.so) and static libraries (.a archives of
relocatable object files).

Linking to a shared library is handled by the runtime loader/linker
(e.g. /lib/ld-linux.so.2). For Linux, ld.so searches the
system-defined directories (/lib, /usr/lib, and those set by
/etc/ld.so.conf), which are cached in /etc/ld.so.cache (created by
ldconfig). This is where distutils runtime_library_dirs comes into
play. For ELF it configures an embedded RPATH, which the loader
searches before the system directories. You can also convert the RPATH
to a RUNPATH, which can be overridden by LD_LIBRARY_PATH.

> Does this mean that the ELF header of the library itself is modified

readelf -d shows the .dynamic section (including strings from
.dynstr), which you can use to verify the RPATH/RUNPATH. chrpath lets
you change (but not add) an RPATH, up to its existing length. It also
lets you convert an RPATH to a RUNPATH. patchELF can add or extend an
RPATH/RUNPATH.

http://nixos.org/patchelf.html

> The libraries I am using are copyrighted (one can freely use them, but
> no reverse engineering, disentangling, etc). I am not sure whether
> adding an rpath will be copyright infringement. Logically, I'd say no,
> but I doubt whether logic applies in legal stuff.

It should be OK for internal administration. You'd have to ask a legal
expert about distribution.

If you stick with LD_LIBRARY_PATH, etc, keep in mind it has to be set
before the process starts, typically in a wrapper script. On Windows,
however, you can modify PATH at runtime.


More information about the Tutor mailing list