Details for Linux Library Path
A small writeup which will discuss the details for Linux Library Path. There are several ways to provide the location to the library files, a few are provided and discussed below.
In order for an executable to find the required libraries to link with during run time, one must configure the system so that the libraries can be found. Methods available: (You have to choose at least one of the following)
Add library directories to be included during dynamic linking to the file /etc/ld.so.conf. In modern Linux you can create individual files for different applications under /etc/ld.so.conf.d. These individual files include path to library files required for the application and are easier to manage.
/usr/X11R6/lib /usr/lib ... .. /usr/lib/sane /usr/lib/mysql /opt/lib
Add the library path to the file (/etc/ld.so.conf or file under /etc/ld.so.conf.d) and then execute the command (as root) ldconfig to configure the linker run-time bindings.
Add specified directory to library cache: (as root)
[[email protected] ~]# ldconfig -n /app/lib
Where /app/lib is the directory containing your library libctest.so
When developing and just adding your current directory use the following:
[[email protected] ~]# ldconfig -n .
Note: Please note that this will NOT permanently configure the system to include this directory. The information will be lost upon system reboot.
Specify the environment variable LD_LIBRARY_PATH to point to the directory paths containing the shared object library. This will specify to the run time loader that the library paths will be used during execution to resolve dependencies.
Following is the variable name for different operating system.
Linux/Solaris: LD_LIBRARY_PATH, SGI: LD_LIBRARYN32_PATH, AIX: LIBPATH, Mac OS X: DYLD_LIBRARY_PATH, HP-UX: SHLIB_PATH
[[email protected] ~]# export LD_LIBRARY_PATH=/app/lib:$LD_LIBRARY_PATH
add to your ~/.bashrc file:
... if [ -d /app/lib ]; then LD_LIBRARY_PATH=/app/lib:$LD_LIBRARY_PATH fi ... export LD_LIBRARY_PATH
This instructs the run time loader to look in the path described by the environment variable LD_LIBRARY_PATH, to resolve shared libraries. This will include the path /app/lib.