I have the following Problem: I\'m trying to create a portable version of my program, so I set rpath to \".\" so all libraries are linked using the relative file path. And t
I set rpath to
.
so all libraries are linked using the relative file path
Using .
in rpath is a poor idea:
.so
files in another directory and run your application from there.The correct way is to use -rpath=$ORIGIN
feature. See man ld.so:
$ORIGIN (or equivalently ${ORIGIN}) This expands to the directory containing the program or shared object. Thus, an application located in somedir/app could be compiled with
gcc -Wl,-rpath,'$ORIGIN/../lib'
so that it finds an associated shared object in somedir/lib no matter where somedir is located in the directory hierarchy. This facilitates the creation of "turn-key" applications that do not need to be installed into special directories, but can instead be unpacked into any directory and still find their own shared objects.
$ORIGIN
syntax is a bit unfortunate because it gets expanded as a variable by both make
and bash
, so you may need to quote it appropriately.
what could lead to linux trying to find the library at the original location instead of at the relative one like all the others
When linking, the library may be specified as -lmylib
or -l:libmylib.so
or -l<path>/libmylib.so
. In the latter case the runtime linker looks for the library in that particular path <path>/libmylib.so
only. See man ld, option -l
for full details. You may like to review your build system linker commands.