Coder Perfect

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


Is shared libraries searched in /usr/local/lib? This is the problem I’m having:

[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 ~]$ 

Asked by Leo Izen

Solution #1

Make sure your LD LIBRARY PATH includes all of the directories you wish to search, and then retest it.

You may immediately test this with:

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

This will limit it to that invocation alone.

Alternatively, you can change the default directories searched in /etc/ It’s possible that /usr/local/lib isn’t included in that file in some Linux distributions.

You may also need to run ldconfig to update the cache in /etc/ (as root, or with sudo).

Answered by paxdiablo

Solution #2


On Debian, include /etc/*.conf is in /etc/, and /etc/ is in /etc/

# libc default configuration

Answered by Boris Burkov

Solution #3

Programs have a built-in (ok, “linked-in”) understanding of where their libraries are located. If a program expects to locate its library in /usr/local/lib, it will find it there.

A tool called ldconfig, as well as a configuration file called /etc/ and, most likely, a /etc/, are used to specify site-specific directories.

Other knobs, such as the environment variable, are listed in “man” 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
. . .

Answered by DigitalRoss

Solution #4

To see if this library is present, type find / -name ‘*’.

sudo gedit /etc/

Add the following lines and save:

include /usr/local/lib
include /usr


Answered by vanloi999

Solution #5, I believe, lists the directories to look for shared objects in the file /etc/ You can also use the LD LIBRARY PATH environment variable.

On Linux, ELF headers may also have an RPATH entry. Run the RPATH entry to see whether it’s correct.

readelf -d ffmpeg | grep RPATH

You’re unlikely to see any results from this. To set the RPATH when compiling, follow these steps:

gcc ... -wl, -rpath=MY_PATH

Use $ORIGIN to get the execution directory.

You can change the RPATH of an existing binary with some applications, such as chrpath.

NOTE: Any setuid program will not utilize LD LIBRARY PATH since it poses a security risk.

Answered by KitsuneYMG

Post is based on