linux - 无法加载库搜索路径上存在的共享库

标签 linux ld autoconf libtool netfilter

我正在尝试执行 nft ,它是从源代码构建的,但它报告

 $ nft
nft: error while loading shared libraries: libnftnl.so.4: cannot open shared object file: No such file or directory

我通过运行 autogen.sh 从源构建了 libmnl、libnftnl、nftables,然后使用以下命令进行配置:

--prefix=/usr/local

这些是/usr/local/lib 的内容:

$ ls -l /usr/local/lib/ | grep libnftnl
-rwxr-xr-x 1 root root      961 Mar  2 20:16 libnftnl.la
lrwxrwxrwx 1 root root       17 Mar  2 20:16 libnftnl.so -> libnftnl.so.4.0.0
lrwxrwxrwx 1 root root       17 Mar  2 20:16 libnftnl.so.4 -> libnftnl.so.4.0.0
-rwxr-xr-x 1 root root   913147 Mar  2 20:16 libnftnl.so.4.0.0

更多信息:

$ ldd $(which nft)
    linux-vdso.so.1 =>  (0x00007ffd7afbf000)
    libmnl.so.0 => /usr/lib/x86_64-linux-gnu/libmnl.so.0 (0x00007fc60181f000)
    libnftnl.so.4 => not found
    libreadline.so.6 => /lib/x86_64-linux-gnu/libreadline.so.6 (0x00007fc6015d8000)
    libgmp.so.10 => /usr/lib/x86_64-linux-gnu/libgmp.so.10 (0x00007fc601364000)
    libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fc600f9f000)
    libtinfo.so.5 => /lib/x86_64-linux-gnu/libtinfo.so.5 (0x00007fc600d75000)
    /lib64/ld-linux-x86-64.so.2 (0x000055a0bd82d000)

我的 ld.so.conf 的内容是:

$ cat /etc/ld.so.conf
/usr/lib/x86_64-linux-gnu/libfakeroot
# libc default configuration
/usr/local/lib
/usr/local/lib/
# Multiarch support
/lib/x86_64-linux-gnu
/usr/lib/x86_64-linux-gnu
/usr/lib/x86_64-linux-gnu/mesa-egl
/usr/lib/x86_64-linux-gnu/mesa
/usr/lib/i386-linux-gnu/mesa
# Legacy biarch compatibility support
/lib32
/usr/lib32
# Legacy biarch compatibility support
/libx32
/usr/libx32

但是如果我将 LD_LIBRARY_PATH 设置为“/usr/local/lib”:

 $ export LD_LIBRARY_PATH=/usr/local/lib
 $ ldd $(which nft)
    linux-vdso.so.1 =>  (0x00007ffedf9b3000)
    libmnl.so.0 => /usr/local/lib/libmnl.so.0 (0x00007fb58a033000)
    libnftnl.so.4 => /usr/local/lib/libnftnl.so.4 (0x00007fb589e0b000)
    libreadline.so.6 => /lib/x86_64-linux-gnu/libreadline.so.6 (0x00007fb589ba3000)
    libgmp.so.10 => /usr/lib/x86_64-linux-gnu/libgmp.so.10 (0x00007fb58992f000)
    libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fb58956a000)
    libmxml.so.1 => /usr/lib/libmxml.so.1 (0x00007fb58935b000)
    libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fb58913d000)
    libtinfo.so.5 => /lib/x86_64-linux-gnu/libtinfo.so.5 (0x00007fb588f14000)
    /lib64/ld-linux-x86-64.so.2 (0x000055a827fb3000)

任何人都可以帮助为什么它无法找到该库,即使它存在于搜索路径中?

最佳答案

正如 @Petesh 所指出的,我忘记运行 ldconfig 。运行 ldconfig 后问题得到解决。

关于linux - 无法加载库搜索路径上存在的共享库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35752412/

相关文章:

regex - 如何根据特定字符长度范围移动文件?

linux - Linux 服务器的新手,关于使用可能不同版本的 MPI 执行二进制文件

Linux 中的 C++ 线程

macos - Qt创建者: Undefined symbols for architecture x86_64

linux - Serilog 在 Linux 上运行时不创建日志文件

linux - ld 在错误的路径中搜索,并搜索错误的库

c - ld 使我的所有函数都链接到头文件中的最后一个函数

makefile - 如何在 include 的子目录中安装 automake 安装头文件

c++ - 如何在 [action-if-true] 中执行多个操作

autotools - 用于 python2 和 python3 的 AM_PATH_PYTHON