About
LD_LIBRARY_PATH is a environment variable that lists directory where executable can search for linux shared library. It's also called the shared library search path.
The value of the environment variable LD_LIBRARY_PATH is a colon-separated (:) set of directories where libraries are searched for first before the standard set of directories.
If you are running on a Solaris system, the LD_LIBRARY_PATH environment variable is used to define the native library path.
Articles Related
Why was it invented?
There were a couple good reasons why it was invented:
- This is useful when debugging a new library or using a non-standard library for special purposes, but be sure you trust those who can control those directories.
- To test out new library routines against an already compiled binary (for either backward compatibility or for new feature testing).
- To have a short term way out in case you wanted to move a set of shared libraries to another location.
Environment Variable
Operating System | Library Path Environment Variable |
---|---|
AIX | LIBPATH |
HP-UX | SHLIB_PATH |
Linux | LD_LIBRARY_PATH |
Solaris | LD_LIBRARY_PATH |
Search in it
Script search_library.sh where the first parameter is the library searched.
#!/bin/bash
IFS=:
for p in ${LD_LIBRARY_PATH}; do
if [ -e ${p}/${1} ]; then
echo ${p}
fi
done
Example:
search_library.sh libodbc.so
/u01/app/oracle/product/fmw/Oracle_BI1/bifoundation/odbc/lib
/u01/app/oracle/product/TimesTen/tt1122/lib
/u01/app/oracle/product/fmw/Oracle_BI1/common/ODBC/Merant/7.1.5/lib
/u01/app/oracle/product/fmw/Oracle_BI1/bifoundation/odbc/lib
/u01/app/oracle/product/TimesTen/tt1122/lib
/u01/app/oracle/product/fmw/Oracle_BI1/common/ODBC/Merant/7.1.5/lib
Documentation / Reference
- When should I set LD_LIBRARY_PATH? The short answer is never.