Coder Perfect

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

Problem

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: libavcore.so.0: 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/libavcodec.so           /usr/local/lib/libavfilter.so
/usr/local/lib/libavcodec.so.52        /usr/local/lib/libavfilter.so.1
/usr/local/lib/libavcodec.so.52.108.0  /usr/local/lib/libavfilter.so.1.74.0
/usr/local/lib/libavcore.a             /usr/local/lib/libavformat.a
/usr/local/lib/libavcore.so            /usr/local/lib/libavformat.so
/usr/local/lib/libavcore.so.0          /usr/local/lib/libavformat.so.52
/usr/local/lib/libavcore.so.0.16.1     /usr/local/lib/libavformat.so.52.94.0
/usr/local/lib/libavdevice.a           /usr/local/lib/libavutil.a
/usr/local/lib/libavdevice.so          /usr/local/lib/libavutil.so
/usr/local/lib/libavdevice.so.52       /usr/local/lib/libavutil.so.50
/usr/local/lib/libavdevice.so.52.2.3   /usr/local/lib/libavutil.so.50.36.0
[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/ld.so.conf. 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/ld.so.cache (as root, or with sudo).

Answered by paxdiablo

Solution #2

From http://tldp.org/HOWTO/Program-Library-HOWTO/shared-libraries.html:

On Debian, include /etc/ld.so.conf.d/*.conf is in /etc/ld.so.conf.d/libc.conf, and /etc/ld.so.conf.d/libc.conf is in /etc/ld.so.conf.d/libc.conf.

# libc default configuration
/usr/local/lib

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/ld.so.conf and, most likely, a /etc/ld.so.conf.d, are used to specify site-specific directories.

Other knobs, such as the environment variable, are listed in “man ld.so.” LD LIBRARY PATH.

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

NAME
       ld.so, ld-linux.so* - dynamic linker/loader

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

…and…

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

NAME
       /sbin/ldconfig - configure dynamic linker run time bindings

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

DESCRIPTION
       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/ld.so.conf, and in the trusted directories (/lib
       and  /usr/lib).  The cache is used by the run-time linker, ld.so or ld-
       linux.so.  ldconfig checks the header and filenames of the libraries it
       encounters  when  determining  which  versions  should have their links
       updated.
. . .

Answered by DigitalRoss

Solution #4

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

sudo gedit /etc/ld.so.conf

Add the following lines and save:

include /usr/local/lib
include /usr

ldconfig

Answered by vanloi999

Solution #5

ld.so, I believe, lists the directories to look for shared objects in the file /etc/ld.so.conf. 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 https://stackoverflow.com/questions/4743233/is-usr-local-lib-searched-for-shared-libraries