Linux - Library Path (LD_LIBRARY_PATH, LIBPATH, SHLIB_PATH)

> Operating System - Kernel (Windows, Unix, Linux) > Linux / Unix

1 - About

LD_LIBRARY_PATH is the search path environment variable for the linux shared library

In Linux, 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.

Advertising

3 - 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.

4 - Environment Variable

Operating System Library Path Environment Variable
AIX LIBPATH
HP-UX SHLIB_PATH
Linux LD_LIBRARY_PATH
Solaris LD_LIBRARY_PATH

5 - 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
Advertising

6 - Documentation / Reference

os/linux/ld_library_path.txt · Last modified: 2018/09/22 17:22 by gerardnico