Facebook Twitter Instagram
    WiredRevolution.com
    • Home
    • About
    • Contact Us
    • Essential Linux Commands
    • Sitemap
    Facebook Twitter Instagram
    WiredRevolution.com
    system administration

    How to correctly use LD_LIBRARY_PATH

    RyanBy RyanOctober 22, 2008Updated:September 21, 201212 Comments2 Mins Read
    Facebook Twitter Pinterest LinkedIn Reddit WhatsApp Email

    The LD_LIBRARY_PATH environment variable contains a colon separated list of paths that the linker uses to resolve library dependencies of ELF executables at run-time. These paths will be given priority over the standard library paths /lib and /usr/lib. The standard paths will still be searched, but only after the list of paths in LD_LIBRARY_PATH has been exhausted.

    The best way to use LD_LIBRARY_PATH is to set it on the command line or script immediately before executing the program. This way you can keep the new LD_LIBRARY_PATH isolated from the rest of your system.

    $ export LD_LIBRARY_PATH="/list/of/library/paths:/another/path"
    $ ./program

    In general it is not a good practice to have LD_LIBRARY_PATH permanently set in your environment. This could lead to unintended side effects as programs can link to unintended libraries producing strange results or unexpectedly crashing. There is also the possibility introducing potential security threats.

    All those warnings aside, if you are using BASH you can set it permanently by placing a line similar to this in your .bashrc in your home directory.

    export LIBRARY_PATH="/list/of/library/paths:/another/path"

    A common case for setting LD_LIBRARY_PATH is when you have an application that requires dynamic libraries which were not installed in the standard library locations.

    You can check if the linker can locate all the required libraries by running the ldd command.

    $ ldd ~/myprogram
    	librt.so.1 => /lib/librt.so.1 (0x00002b4eca08e000)
    	libc.so.6 => /lib/libc.so.6 (0x00002b4eca49f000)
    	libpthread.so.0 => /lib/libpthread.so.0 (0x00002b4eca7df000)
    	/lib64/ld-linux-x86-64.so.2 (0x00002b4ec9e72000)
    	libmylib.so.1 => not found

    The linker cannot find libmylib.so.1.

    Let’s assume this library exists here “~/myprogdir/lib/libmylib.so.1”. We have to set LD_LIBRARY_PATH to include this path for the application to successfully run.

    $ export LD_LIBRARY_PATH="~/myprogdir/lib/:$LD_LIBRARY_PATH"
    $ ldd ~/myprogram
    	librt.so.1 => /lib/librt.so.1 (0x00002b4eca08e000)
    	libc.so.6 => /lib/libc.so.6 (0x00002b4eca49f000)
    	libpthread.so.0 => /lib/libpthread.so.0 (0x00002b4eca7df000)
    	/lib64/ld-linux-x86-64.so.2 (0x00002b4ec9e72000)
    	libmylib.so.1 => ~/myprogdir/lib/libmylib.so.1 (0x00002b4eca9fa000)

    The linker has now found all the required libraries.

    Share. Facebook Twitter Pinterest LinkedIn WhatsApp Reddit Email
    Previous ArticleSearch for files with the find command
    Next Article RPM Cheat Sheet

    Related Posts

    Safely and atomically change a symlink target

    Fix git-upload-pack and git-receive-pack errors on shared hosting

    Find the PID of the current Bash script

    Most Commented
    March 12, 2009

    Fix blue tinted video in Ubuntu

    September 10, 2010

    Setup SSH access between VirtualBox Host and Guest VMs

    March 8, 2011

    Install GNOME Shell in Ubuntu 10.10 Maverick

    April 4, 2009

    Setup the PS3 Bluetooth Controller on Ubuntu

    October 22, 2008

    How to correctly use LD_LIBRARY_PATH

    Recent Comments
    • Execute command on linux virtual machine (or server) from windows commandline on Setup SSH access between VirtualBox Host and Guest VMs
    • Solved: How to SSH to a VirtualBox guest externally through a host? - Daily Developer Blog on Setup SSH access between VirtualBox Host and Guest VMs
    • How to SSH to a VirtualBox guest externally through a host? [closed] – Code D3 on Setup SSH access between VirtualBox Host and Guest VMs
    • How to copy and paste from VirtualBox? [duplicate] on Setup SSH access between VirtualBox Host and Guest VMs
    • Jackie Laguna on Fix OpenGL: ChoosePixelFormat SketchUp error in WINE
    © 2025 ThemeSphere. Designed by ThemeSphere.

    Type above and press Enter to search. Press Esc to cancel.