Specifying the RUNPATH in sofiles

When you create a shared object that depends on another shared object there are multiple ways to tell it where to look for the shared object. Two of these are by encoding (at linking time) a DT_RPATH and DT_RUNPATH entry in the .dynamic section. A third one is to use the LD_LIBRARY_PATH environment variable (at runtime). The order of precedence of these is:

The question is how to encode these into your shared object. This is normally done with the --rpath or -R options to the linker. But as the name suggest this will create an RPATH. When using GNU ld(1) you add an --enable-new-dtags option which does add the (newer) RUNPATH, and when both RPATH and RUNPATH are present the runtime linker will ignore the RPATH. On Solaris however the linker does add a RUNPATH by default as soon as you use -R, thus you will always end up with LD_LIBRARY_PATH overriding the value you gave with -R. Good to keep that in mind.