RPath/RunPath



About

Hardcoding the library path into a library/executable.

Setting the rpath is a way of hard coding a location of a dependant library inside a binary executable. This saves you having to rely on system directories and is a technique oft employed by build systems prior to the install step so libraries can be found for demo/test programs. 

Setting the runpath is similar, but it does not override LD_LIBRARY_PATH nor system paths.

Usage


Linking
 -Wl, -rpath,/opt/ros/ycs/mdb/lib -lmdb


Lising RPaths
readelf -d <binary> | grep RPATH


Modifying


There is a program called chrpath which can modify an existing rpath command. It has a gentoo ebuild, I'm not sure about ubuntu. It has one problem which really negates its usefulness (though its still useful for investigating rpaths) - when replacing the rpath, you aren't permitted to replace it with something longer than the original rpath.