[Nix-dev] Why not use SONAME instead of RPATH

Silvio Frischknecht yokto at lupux.ch
Sun Apr 17 18:02:01 CEST 2016


Hello,

I recently found out that if you set the SONAME of a library to an
absolute path.

gcc --shared -Wl,-soname="$(pwd)/libxyz.so" -o libxyz.so  libxyz.c

and then later link to it

gcc main.c -L. -lxyz

the dynamic linker will only look for the library in the exact path
specified when compiling the library.

Advantages over RPATH:
+ probably faster since rpaths in nixos tend to be quite long and every
library has to be looked for in every folder (linear vs quadratic
complexity)
+ only has to be setup once per library - all referrers will
automatically work correctly

In this case the path can't be overwritten by LD_LIBRARY_PATH. I guess
that could be an advantage or a disadvantage depending on how you look
at it.

Cheers

Silvio


More information about the nix-dev mailing list