共享庫可以與您的可執行文件位於同一個文件夾中。 man ld.so:
$ORIGIN and rpath
ld.so understands the string $ORIGIN (or equivalently ${ORIGIN}) in an
rpath specification (DT_RPATH or DT_RUNPATH) to mean the directory con-
taining the application executable. Thus, an application located in
somedir/app could be compiled with gcc -Wl,-rpath,'$ORIGIN/../lib' so
that it finds an associated shared library 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 libraries.
好的解決方案。缺點是'$ ORIGIN'這個詞的可怕選擇,它需要在每個shell和構建系統中進行某種轉義。 – ephemient 2011-01-19 23:47:51