Is /usr/local/lib searched for shared libraries?

LinuxLinkerFfmpegShared Libraries

Linux Problem Overview

Is /usr/local/lib searched for shared libraries ? I have this error:

[Leo@chessman ~]$ whereis ffmpeg
ffmpeg: /usr/local/bin/ffmpeg
[Leo@chessman ~]$ ffmpeg
ffmpeg: error while loading shared libraries: cannot open shared object file: No such file or directory
[Leo@chessman ~]$ ls /usr/local/lib/libav*
/usr/local/lib/libavcodec.a            /usr/local/lib/libavfilter.a
/usr/local/lib/           /usr/local/lib/
/usr/local/lib/        /usr/local/lib/
/usr/local/lib/  /usr/local/lib/
/usr/local/lib/libavcore.a             /usr/local/lib/libavformat.a
/usr/local/lib/            /usr/local/lib/
/usr/local/lib/          /usr/local/lib/
/usr/local/lib/     /usr/local/lib/
/usr/local/lib/libavdevice.a           /usr/local/lib/libavutil.a
/usr/local/lib/          /usr/local/lib/
/usr/local/lib/       /usr/local/lib/
/usr/local/lib/   /usr/local/lib/
[Leo@chessman ~]$ 

Linux Solutions

Solution 1 - Linux

Make sure your LD_LIBRARY_PATH is set up to include all directories you want to search and then test it again.

You can test this quickly with:

LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib ffmpeg

which will set it only for that invocation.

Alternatively, you can edit /etc/ which contains the default directories searched. Some Linux distributions may not include /usr/local/lib in that file.

Note that you may also need to update the cache /etc/ by running ldconfig (as root, or with sudo).

Solution 2 - Linux


> The GNU standards recommend installing by default all libraries in /usr/local/lib when distributing source code (and all commands should go into /usr/local/bin).


> The list of directories to be searched is stored in the file /etc/ Many Red Hat-derived distributions don't normally include /usr/local/lib in the file /etc/ I consider this a bug, and adding /usr/local/lib to /etc/ is a common ``fix'' required to run many programs on Red Hat-derived systems.

On Debian /etc/ contains include /etc/*.conf, and /etc/ contains

# libc default configuration

Solution 3 - Linux

Yes and no

Programs have a compiled-in (ok, "linked-in") idea of where their libraries are to be found. If a program is expecting to find its lib in /usr/local/lib then it will.

There is also a program called ldconfig and a configuration file called /etc/ and most likely an /etc/, and these are used to specify site-specific directories.

Read "man" which lists other knobs like the environment variable LD_LIBRARY_PATH.

LD.SO(8)                   Linux Programmer’s Manual                  LD.SO(8)

NAME,* - dynamic linker/loader

       The  programs and* find and load the shared libraries
       needed by a program, prepare the program to run, and then run it.
. . .


LDCONFIG(8)                Linux Programmer’s Manual               LDCONFIG(8)

       /sbin/ldconfig - configure dynamic linker run time bindings

       /sbin/ldconfig  [  -nNvXV ] [ -f conf ] [ -C cache ] [ -r root ] direc-
       tory ...
       /sbin/ldconfig -l [ -v ] library ...
       /sbin/ldconfig -p

       ldconfig creates the necessary links  and  cache  to  the  most  recent
       shared  libraries  found  in  the  directories specified on the command
       line, in the file /etc/, and in the trusted directories (/lib
       and  /usr/lib).  The cache is used by the run-time linker, or ld-  ldconfig checks the header and filenames of the libraries it
       encounters  when  determining  which  versions  should have their links
. . .

Solution 4 - Linux

find / -name '*' to find out whether this library is available.

sudo gedit /etc/

Add these lines and save:

include /usr/local/lib
include /usr


Solution 5 - Linux

IIRC, uses the file /etc/ to list the directories to search for shared objects. You may also use the environment variable LD_LIBRARY_PATH.

ELF headers on linux may also contain an RPATH entry. To check the RPATH entry run

readelf -d ffmpeg | grep RPATH

You will probably not get any result from this. To set the RPATH while compiling do:

gcc ... -wl, -rpath=MY_PATH

If you want the execution directory use \$ORIGIN

Some programs, such as chrpath, allow you to edit the RPATH of an existing binary.

NOTE: Any program that is setuid will not use LD_LIBRARY_PATH as it is a security risk.

Solution 6 - Linux

Another option for this old question is to use LD_RUN_PATH.

export LD_RUN_PATH=/usr/local/lib

Then compile again:

make install

Better than using LD_LIBRARY_PATH. Original reference from @cweiske


All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionLeo IzenView Question on Stackoverflow
Solution 1 - LinuxpaxdiabloView Answer on Stackoverflow
Solution 2 - LinuxBoris BurkovView Answer on Stackoverflow
Solution 3 - LinuxDigitalRossView Answer on Stackoverflow
Solution 4 - Linuxvanloi999View Answer on Stackoverflow
Solution 5 - LinuxKitsuneYMGView Answer on Stackoverflow
Solution 6 - LinuxTomView Answer on Stackoverflow