Linux 是否在 /usr/local/lib 中搜索共享库?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4743233/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Is /usr/local/lib searched for shared libraries?
提问by Leo Izen
Is /usr/local/lib
searched for shared libraries ? I have this error:
是否/usr/local/lib
搜索共享库?我有这个错误:
[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 ~]$
采纳答案by paxdiablo
Make sure your LD_LIBRARY_PATH
is set up to include all directories you want to search and then test it again.
确保您LD_LIBRARY_PATH
已设置为包含要搜索的所有目录,然后再次测试。
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/ld.so.conf
which contains the default directories searched. Some Linux distributions may not include /usr/local/lib
in that file.
或者,您可以编辑/etc/ld.so.conf
其中包含搜索的默认目录。某些 Linux 发行版可能不包含/usr/local/lib
在该文件中。
Note that you may also need to update the cache /etc/ld.so.cache
by running ldconfig
(as root, or with sudo
).
请注意,您可能还需要/etc/ld.so.cache
通过运行ldconfig
(以 root 身份或使用sudo
)来更新缓存。
回答by DigitalRoss
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.
程序对在哪里可以找到它们的库有一个编译(好的,“链接”)的想法。如果一个程序希望在其中找到它的库,/usr/local/lib
那么它会。
There is also a program called ldconfig
and a configuration file called /etc/ld.so.conf
and most likely an /etc/ld.so.conf.d
, and these are used to specify site-specific directories.
还有一个名为的程序ldconfig
和一个名为的配置文件/etc/ld.so.conf
,很可能是一个/etc/ld.so.conf.d
,它们用于指定特定于站点的目录。
Read "man ld.so" which lists other knobs like the environment variable LD_LIBRARY_PATH
.
阅读“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.
. . .
回答by KitsuneYMG
IIRC, ld.so uses the file /etc/ld.so.conf to list the directories to search for shared objects. You may also use the environment variable LD_LIBRARY_PATH
.
IIRC, ld.so 使用文件 /etc/ld.so.conf 列出搜索共享对象的目录。您也可以使用环境变量LD_LIBRARY_PATH
。
ELF headers on linux may also contain an RPATH entry. To check the RPATH entry run
Linux 上的 ELF 标头也可能包含 RPATH 条目。要检查 RPATH 条目,请运行
readelf -d ffmpeg | grep RPATH
You will probably not get any result from this. To set the RPATH while compiling do:
你可能不会得到任何结果。要在编译时设置 RPATH,请执行以下操作:
gcc ... -wl, -rpath=MY_PATH
If you want the execution directory use \$ORIGIN
如果你想要执行目录使用 \$ORIGIN
Some programs, such as chrpath, allow you to edit the RPATH of an existing binary.
某些程序,例如 chrpath,允许您编辑现有二进制文件的 RPATH。
NOTE: Any program that is setuid will not use LD_LIBRARY_PATH
as it is a security risk.
注意:任何设置为 setuid 的程序都不会使用,LD_LIBRARY_PATH
因为它存在安全风险。
回答by vanloi999
find / -name 'libavdevice.so.*'
to find out whether this library is available.
find / -name 'libavdevice.so.*'
找出这个库是否可用。
sudo gedit /etc/ld.so.conf
sudo gedit /etc/ld.so.conf
Add these lines and save:
添加这些行并保存:
include /usr/local/lib
include /usr
ldconfig
ldconfig
回答by Tom
Another option for this old question is to use LD_RUN_PATH.
这个老问题的另一个选择是使用 LD_RUN_PATH。
export LD_RUN_PATH=/usr/local/lib
Then compile again:
然后再次编译:
make
make install
ldconfig
Better than using LD_LIBRARY_PATH. Original reference from @cweiske linuxmafia.com/faq/Admin/ld-lib-path.html
比使用 LD_LIBRARY_PATH 更好。来自@cweiske linuxmafia.com/faq/Admin/ld-lib-path.html 的原始参考
回答by Boris Burkov
From http://tldp.org/HOWTO/Program-Library-HOWTO/shared-libraries.html:
来自http://tldp.org/HOWTO/Program-Library-HOWTO/shared-libraries.html:
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).
GNU 标准建议在分发源代码时默认将所有库安装在 /usr/local/lib 中(并且所有命令都应进入 /usr/local/bin)。
...
...
The list of directories to be searched is stored in the file /etc/ld.so.conf. Many Red Hat-derived distributions don't normally include /usr/local/lib in the file /etc/ld.so.conf. I consider this a bug, and adding /usr/local/lib to /etc/ld.so.conf is a common ``fix'' required to run many programs on Red Hat-derived systems.
要搜索的目录列表存储在文件 /etc/ld.so.conf 中。许多 Red Hat 派生的发行版通常不会在文件 /etc/ld.so.conf 中包含 /usr/local/lib。我认为这是一个错误,将 /usr/local/lib 添加到 /etc/ld.so.conf 是在 Red Hat 派生系统上运行许多程序所需的常见“修复”。
On Debian /etc/ld.so.conf
contains include /etc/ld.so.conf.d/*.conf
, and /etc/ld.so.conf.d/libc.conf
contains
在 Debian 上/etc/ld.so.conf
包含include /etc/ld.so.conf.d/*.conf
,并且/etc/ld.so.conf.d/libc.conf
包含
# libc default configuration
/usr/local/lib