what is the difference between LD_LIBRARY_PATH and -rpath

Ju Liu picture Ju Liu · Nov 29, 2012 · Viewed 9.6k times · Source

When linking libraries, -rpath is used to pass the address of dynamic libraries to ld. My question is if I set the address in LD_LIBRARY_PATH, do I still need -rpath flag in my linking process?

Answer

chill picture chill · Nov 29, 2012

Generally, you don't need it and in fact it's preferable to not have the library search path encoded in the executable (the -rpath option encodes the path in the binary, either as DT_RPATH or DR_RUNPATH)

PS. My own general approach is to link executables with the --rpath option, while they are in build tree and depend on other libraries in the build tree, to facilitate debugging, but upon installation (make install, building packages) to re-link without --rpath option and leave the task of finding the shared libraries to the appropriate dynamic linker configuration (e.g. ld.so.conf) of the target platform.