Home

RPATH

RPATH is a runtime library search path embedded in an executable or shared library on many Unix-like systems. It tells the dynamic linker where to look for required shared libraries when the program starts. The path information is added at link time via the linker option -rpath (for example, -Wl,-rpath,/opt/mylib/lib) and is stored in the executable’s dynamic section as DT_RPATH or DT_RUNPATH.

In ELF binaries, DT_RUNPATH is the modern field, while DT_RPATH is the older one. When both may

RPATH is often considered less flexible than RUNPATH for relocatable installations. RUNPATH is generally favored because

A common technique to improve relocatability is to use relative paths, such as $ORIGIN, which expands to

Security and portability considerations apply: embedding absolute paths can hinder relocation and may complicate packaging or

be
present,
runtimes
generally
prefer
RUNPATH
for
compatibility
with
environment
overrides.
In
practice,
a
binary
with
an
RPATH
or
RUNPATH
cause
the
dynamic
linker
to
search
those
directories
before,
or
as
part
of,
the
standard
system
library
paths,
affecting
how
dependencies
are
resolved
at
startup.
it
allows
environment
variables,
notably
LD_LIBRARY_PATH,
to
influence
the
search
order,
making
it
easier
to
adapt
a
binary
to
different
environments
without
rebuilding
it.
the
directory
containing
the
executable.
For
example,
-Wl,-rpath,'$ORIGIN/../lib'
makes
the
runtime
search
relative
to
the
binary’s
location.
updates.
When
possible,
use
RUNPATH
with
relative
paths
or
rely
on
system
library
locations
and
packaging
mechanisms
to
manage
dependencies.
LD_LIBRARY_PATH
can
alter
search
behavior
at
runtime,
depending
on
the
system
and
linker
configuration.