╰─➤ ldd libx264-2881b7ff.so.164
linux-vdso.so.1 (0x00007fff1bec0000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f9f37919000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f9f37d5c000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f9f37d57000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f9f37600000)
/lib64/ld-linux-x86-64.so.2 (0x00007f9f37d77000)
比如上面的输出,哪些是「绝对」,哪些是「相对」呢?
我觉得 /lib64/ld-linux-x86-64.so.2 (0x00007f9f37d77000)
是绝对
linux-vdso.so.1 (0x00007fff1bec0000)
是相对
但是类似 libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f9f37d5c000)
这样的算绝对还是相对引用呢?这里的 =>
表示什么含义呢?
我有一个问题,就是「如果没有 / ,那么就按找一个特定的方式在在磁盘上寻找这个文件。这个时候,ldd 会用 => 显示寻找的结果。」,我安装了一个 pyav,通过 pip install av
安装,然后我查看 av 的一个动态链接库
ldd _core.cpython-310-x86_64-linux-gnu.so
,发现这个动态链接库里面的 => 都是指向 /home/pon/.local/share/virtualenvs/svddb_sdk-qAt4tE2E/lib/python3.10/site-packages/av/./../av.libs
里面的某个文件,我不清楚这个「特定的方式」是什么?
(svddb_sdk) ╭─pon@admini ~/.local/share/virtualenvs/svddb_sdk-qAt4tE2E/lib/python3.10/site-packages/av
╰─➤ ldd _core.cpython-310-x86_64-linux-gnu.so
linux-vdso.so.1 (0x00007ffc8db53000)
libavformat-20d4e1d0.so.59.27.100 => /home/pon/.local/share/virtualenvs/svddb_sdk-qAt4tE2E/lib/python3.10/site-packages/av/./../av.libs/libavformat-20d4e1d0.so.59.27.100 (0x00007fd001254000)
libavcodec-8a88085f.so.59.37.100 => /home/pon/.local/share/virtualenvs/svddb_sdk-qAt4tE2E/lib/python3.10/site-packages/av/./../av.libs/libavcodec-8a88085f.so.59.37.100 (0x00007fcffff37000)
libavdevice-ed40abdd.so.59.7.100 => /home/pon/.local/share/virtualenvs/svddb_sdk-qAt4tE2E/lib/python3.10/site-packages/av/./../av.libs/libavdevice-ed40abdd.so.59.7.100 (0x00007fcffff18000)
libavutil-1701948d.so.57.28.100 => /home/pon/.local/share/virtualenvs/svddb_sdk-qAt4tE2E/lib/python3.10/site-packages/av/./../av.libs/libavutil-1701948d.so.57.28.100 (0x00007fcfffd3a000)
libavfilter-2d5314ec.so.8.44.100 => /home/pon/.local/share/virtualenvs/svddb_sdk-qAt4tE2E/lib/python3.10/site-packages/av/./../av.libs/libavfilter-2d5314ec.so.8.44.100 (0x00007fcfff8e9000)
libswscale-a6aee226.so.6.7.100 => /home/pon/.local/share/virtualenvs/svddb_sdk-qAt4tE2E/lib/python3.10/site-packages/av/./../av.libs/libswscale-a6aee226.so.6.7.100 (0x00007fcfff846000)
libswresample-b868a3ce.so.4.7.100 => /home/pon/.local/share/virtualenvs/svddb_sdk-qAt4tE2E/lib/python3.10/site-packages/av/./../av.libs/libswresample-b868a3ce.so.4.7.100 (0x00007fcfff824000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fcfff7f5000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fcfff603000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fcfff4b4000)
libxml2-47a785fa.so.2.9.13 => /home/pon/.local/share/virtualenvs/svddb_sdk-qAt4tE2E/lib/python3.10/site-packages/av/./../av.libs/libxml2-47a785fa.so.2.9.13 (0x00007fcfff328000)
libbluray-69850b93.so.2.1.2 => /home/pon/.local/share/virtualenvs/svddb_sdk-qAt4tE2E/lib/python3.10/site-packages/av/./../av.libs/libbluray-69850b93.so.2.1.2 (0x00007fcfff2d3000)
libgmp-dbb9f291.so.10.4.1 => /home/pon/.local/share/virtualenvs/svddb_sdk-qAt4tE2E/lib/python3.10/site-packages/av/./../av.libs/libgmp-dbb9f291.so.10.4.1 (0x00007fcfff25a000)
libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007fcfff23e000)
libgnutls-58994bd7.so.30.31.0 => /home/pon/.local/share/virtualenvs/svddb_sdk-qAt4tE2E/lib/python3.10/site-packages/av/./../av.libs/libgnutls-58994bd7.so.30.31.0 (0x00007fcfff005000)
libvpx-c1705a7a.so.7.0.0 => /home/pon/.local/share/virtualenvs/svddb_sdk-qAt4tE2E/lib/python3.10/site-packages/av/./../av.libs/libvpx-c1705a7a.so.7.0.0 (0x00007fcffedf0000)
liblzma-f3a5963b.so.5.2.5 => /home/pon/.local/share/virtualenvs/svddb_sdk-qAt4tE2E/lib/python3.10/site-packages/av/./../av.libs/liblzma-f3a5963b.so.5.2.5 (0x00007fcffedc5000)
libdav1d-df61568f.so.5.1.1 => /home/pon/.local/share/virtualenvs/svddb_sdk-qAt4tE2E/lib/python3.10/site-packages/av/./../av.libs/libdav1d-df61568f.so.5.1.1 (0x00007fcffebff000)
libopencore-amrwb-9db94aa9.so.0.0.3 => /home/pon/.local/share/virtualenvs/svddb_sdk-qAt4tE2E/lib/python3.10/site-packages/av/./../av.libs/libopencore-amrwb-9db94aa9.so.0.0.3 (0x00007fcffebe9000)
libaom-e9efed4a.so.3.2.0 => /home/pon/.local/share/virtualenvs/svddb_sdk-qAt4tE2E/lib/python3.10/site-packages/av/./../av.libs/libaom-e9efed4a.so.3.2.0 (0x00007fcffe4a9000)
libmp3lame-3ecc6556.so.0.0.0 => /home/pon/.local/share/virtualenvs/svddb_sdk-qAt4tE2E/lib/python3.10/site-packages/av/./../av.libs/libmp3lame-3ecc6556.so.0.0.0 (0x00007fcffe415000)
libopencore-amrnb-393dbae2.so.0.0.3 => /home/pon/.local/share/virtualenvs/svddb_sdk-qAt4tE2E/lib/python3.10/site-packages/av/./../av.libs/libopencore-amrnb-393dbae2.so.0.0.3 (0x00007fcffe3e7000)
libopenjp2-0d101c52.so.2.4.0 => /home/pon/.local/share/virtualenvs/svddb_sdk-qAt4tE2E/lib/python3.10/site-packages/av/./../av.libs/libopenjp2-0d101c52.so.2.4.0 (0x00007fcffe363000)
libopus-70bda348.so.0.8.0 => /home/pon/.local/share/virtualenvs/svddb_sdk-qAt4tE2E/lib/python3.10/site-packages/av/./../av.libs/libopus-70bda348.so.0.8.0 (0x00007fcffe307000)
libspeex-b6a53f7a.so.1.5.1 => /home/pon/.local/share/virtualenvs/svddb_sdk-qAt4tE2E/lib/python3.10/site-packages/av/./../av.libs/libspeex-b6a53f7a.so.1.5.1 (0x00007fcffe2eb000)
libtheoraenc-276df146.so.1.1.2 => /home/pon/.local/share/virtualenvs/svddb_sdk-qAt4tE2E/lib/python3.10/site-packages/av/./../av.libs/libtheoraenc-276df146.so.1.1.2 (0x00007fcffe2a9000)
libtheoradec-f01ee89e.so.1.1.4 => /home/pon/.local/share/virtualenvs/svddb_sdk-qAt4tE2E/lib/python3.10/site-packages/av/./../av.libs/libtheoradec-f01ee89e.so.1.1.4 (0x00007fcffe287000)
libtwolame-72d74ef7.so.0.0.0 => /home/pon/.local/share/virtualenvs/svddb_sdk-qAt4tE2E/lib/python3.10/site-packages/av/./../av.libs/libtwolame-72d74ef7.so.0.0.0 (0x00007fcffe25e000)
libvorbis-f4a9a6fd.so.0.4.9 => /home/pon/.local/share/virtualenvs/svddb_sdk-qAt4tE2E/lib/python3.10/site-packages/av/./../av.libs/libvorbis-f4a9a6fd.so.0.4.9 (0x00007fcffe221000)
libvorbisenc-0d9d5bdf.so.2.0.12 => /home/pon/.local/share/virtualenvs/svddb_sdk-qAt4tE2E/lib/python3.10/site-packages/av/./../av.libs/libvorbisenc-0d9d5bdf.so.2.0.12 (0x00007fcffe170000)
libx264-2881b7ff.so.164 => /home/pon/.local/share/virtualenvs/svddb_sdk-qAt4tE2E/lib/python3.10/site-packages/av/./../av.libs/libx264-2881b7ff.so.164 (0x00007fcffde4d000)
libx265-d8690e8d.so.199 => /home/pon/.local/share/virtualenvs/svddb_sdk-qAt4tE2E/lib/python3.10/site-packages/av/./../av.libs/libx265-d8690e8d.so.199 (0x00007fcffcbc1000)
libxvidcore-d29bca61.so.4.3 => /home/pon/.local/share/virtualenvs/svddb_sdk-qAt4tE2E/lib/python3.10/site-packages/av/./../av.libs/libxvidcore-d29bca61.so.4.3 (0x00007fcffcab3000)
libxcb-65da195c.so.1.1.0 => /home/pon/.local/share/virtualenvs/svddb_sdk-qAt4tE2E/lib/python3.10/site-packages/av/./../av.libs/libxcb-65da195c.so.1.1.0 (0x00007fcffc880000)
libxcb-shm-7a199f70.so.0.0.0 => /home/pon/.local/share/virtualenvs/svddb_sdk-qAt4tE2E/lib/python3.10/site-packages/av/./../av.libs/libxcb-shm-7a199f70.so.0.0.0 (0x00007fcffc679000)
libxcb-shape-25c2b258.so.0.0.0 => /home/pon/.local/share/virtualenvs/svddb_sdk-qAt4tE2E/lib/python3.10/site-packages/av/./../av.libs/libxcb-shape-25c2b258.so.0.0.0 (0x00007fcffc472000)
libxcb-xfixes-9be3ba6f.so.0.0.0 => /home/pon/.local/share/virtualenvs/svddb_sdk-qAt4tE2E/lib/python3.10/site-packages/av/./../av.libs/libxcb-xfixes-9be3ba6f.so.0.0.0 (0x00007fcffc262000)
libpostproc-9d3ac700.so.56.6.100 => /home/pon/.local/share/virtualenvs/svddb_sdk-qAt4tE2E/lib/python3.10/site-packages/av/./../av.libs/libpostproc-9d3ac700.so.56.6.100 (0x00007fcffc240000)
libass-8499ab98.so.9.1.3 => /home/pon/.local/share/virtualenvs/svddb_sdk-qAt4tE2E/lib/python3.10/site-packages/av/./../av.libs/libass-8499ab98.so.9.1.3 (0x00007fcffc1fe000)
libfontconfig-99ba2620.so.1.12.0 => /home/pon/.local/share/virtualenvs/svddb_sdk-qAt4tE2E/lib/python3.10/site-packages/av/./../av.libs/libfontconfig-99ba2620.so.1.12.0 (0x00007fcffc1aa000)
libfreetype-19bd6cfb.so.6.17.1 => /home/pon/.local/share/virtualenvs/svddb_sdk-qAt4tE2E/lib/python3.10/site-packages/av/./../av.libs/libfreetype-19bd6cfb.so.6.17.1 (0x00007fcffc0f9000)
/lib64/ld-linux-x86-64.so.2 (0x00007fd0014fe000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007fcffc0f1000)
libunistring-aeeab030.so.2.1.0 => /home/pon/.local/share/virtualenvs/svddb_sdk-qAt4tE2E/lib/python3.10/site-packages/av/./../av.libs/libunistring-aeeab030.so.2.1.0 (0x00007fcffbf6a000)
libnettle-cb75a9d6.so.8.4 => /home/pon/.local/share/virtualenvs/svddb_sdk-qAt4tE2E/lib/python3.10/site-packages/av/./../av.libs/libnettle-cb75a9d6.so.8.4 (0x00007fcffbf1f000)
libhogweed-5d799758.so.6.4 => /home/pon/.local/share/virtualenvs/svddb_sdk-qAt4tE2E/lib/python3.10/site-packages/av/./../av.libs/libhogweed-5d799758.so.6.4 (0x00007fcffbece000)
libstdc++.so.6 => /lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007fcffbcec000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007fcffbccf000)
libogg-bbd52b06.so.0.8.5 => /home/pon/.local/share/virtualenvs/svddb_sdk-qAt4tE2E/lib/python3.10/site-packages/av/./../av.libs/libogg-bbd52b06.so.0.8.5 (0x00007fcffbcc3000)
librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007fcffbcb9000)
libXau-00ec42fe.so.6.0.0 => /home/pon/.local/share/virtualenvs/svddb_sdk-qAt4tE2E/lib/python3.10/site-packages/av/./../av.libs/libXau-00ec42fe.so.6.0.0 (0x00007fcffbab4000)
libfribidi-baef595b.so.0.4.0 => /home/pon/.local/share/virtualenvs/svddb_sdk-qAt4tE2E/lib/python3.10/site-packages/av/./../av.libs/libfribidi-baef595b.so.0.4.0 (0x00007fcffba91000)
libharfbuzz-d40f381a.so.0.40100.0 => /home/pon/.local/share/virtualenvs/svddb_sdk-qAt4tE2E/lib/python3.10/site-packages/av/./../av.libs/libharfbuzz-d40f381a.so.0.40100.0 (0x00007fcffb97d000)
libuuid-f64cda11.so.1.3.0 => /home/pon/.local/share/virtualenvs/svddb_sdk-qAt4tE2E/lib/python3.10/site-packages/av/./../av.libs/libuuid-f64cda11.so.1.3.0 (0x00007fcffb777000)
libpng16-1f529098.so.16.37.0 => /home/pon/.local/share/virtualenvs/svddb_sdk-qAt4tE2E/lib/python3.10/site-packages/av/./../av.libs/libpng16-1f529098.so.16.37.0 (0x00007fcffb746000)
比如其中的 libavformat-20d4e1d0.so.59.27.100 => /home/pon/.local/share/virtualenvs/svddb_sdk-qAt4tE2E/lib/python3.10/site-packages/av/./../av.libs/libavformat-20d4e1d0.so.59.27.100 (0x00007fd001254000)
这个是按照什么规定让 libavformat-20d4e1d0.so.59.27.100
指向 /home/pon/.local/share/virtualenvs/svddb_sdk-qAt4tE2E/lib/python3.10/site-packages/av/./../av.libs/libavformat-20d4e1d0.so.59.27.100 (0x00007fd001254000)
的呢?按理来说,/home/pon/.local/share/virtualenvs/svddb_sdk-qAt4tE2E/lib/python3.10/site-packages/av/./../av.libs/
不应该存在于系统的默认搜索路径中吧?而且我也没有添加类似 LD_LIBRARY_PATH、LD_PRELOAD、LD_LIBRARYN、LD_DEBUG、LD_BIND_NOW 的环境变量
(svddb_sdk) ╭─pon@admini ~/.local/share/virtualenvs/svddb_sdk-qAt4tE2E/lib/python3.10/site-packages/av
╰─➤ printenv | grep LD_ 1 ↵
(svddb_sdk) ╭─pon@admini ~/.local/share/virtualenvs/svddb_sdk-qAt4tE2E/lib/python3.10/site-packages/av
如果使用 readelf 查看,就是下面这样
─➤ readelf -d _core.cpython-310-x86_64-linux-gnu.so 1 ↵
Dynamic section at offset 0x2d000 contains 33 entries:
Tag Type Name/Value
0x000000000000000f (RPATH) Library rpath: [$ORIGIN/../av.libs]
0x0000000000000001 (NEEDED) Shared library: [libavformat-20d4e1d0.so.59.27.100]
0x0000000000000001 (NEEDED) Shared library: [libavcodec-8a88085f.so.59.37.100]
0x0000000000000001 (NEEDED) Shared library: [libavdevice-ed40abdd.so.59.7.100]
0x0000000000000001 (NEEDED) Shared library: [libavutil-1701948d.so.57.28.100]
0x0000000000000001 (NEEDED) Shared library: [libavfilter-2d5314ec.so.8.44.100]
0x0000000000000001 (NEEDED) Shared library: [libswscale-a6aee226.so.6.7.100]
0x0000000000000001 (NEEDED) Shared library: [libswresample-b868a3ce.so.4.7.100]
0x0000000000000001 (NEEDED) Shared library: [libpthread.so.0]
0x0000000000000001 (NEEDED) Shared library: [libc.so.6]
0x000000000000000c (INIT) 0x3000
0x000000000000000d (FINI) 0x63c4
0x0000000000000019 (INIT_ARRAY) 0x8cd8
0x000000000000001b (INIT_ARRAYSZ) 8 (bytes)
0x000000000000001a (FINI_ARRAY) 0x8ce0
0x000000000000001c (FINI_ARRAYSZ) 8 (bytes)
0x000000006ffffef5 (GNU_HASH) 0xb358
0x0000000000000005 (STRTAB) 0x12250
0x0000000000000006 (SYMTAB) 0xa8d8
0x000000000000000a (STRSZ) 2479 (bytes)
0x000000000000000b (SYMENT) 24 (bytes)
0x0000000000000003 (PLTGOT) 0x9000
0x0000000000000002 (PLTRELSZ) 2016 (bytes)
0x0000000000000014 (PLTREL) RELA
0x0000000000000017 (JMPREL) 0x1e40
0x0000000000000007 (RELA) 0x17b0
0x0000000000000008 (RELASZ) 1680 (bytes)
0x0000000000000009 (RELAENT) 24 (bytes)
0x000000006ffffffe (VERNEED) 0x16b0
0x000000006fffffff (VERNEEDNUM) 8
0x000000006ffffff0 (VERSYM) 0x15ce
0x000000006ffffff9 (RELACOUNT) 44
0x0000000000000000 (NULL) 0x0
ldd 列出来的始终都是绝对路径。
你误解
linux-vdso.so
了是“相对路径”可能是因为它开头没带着/
吧。这是因为它在内核里,是个虚拟的文件(VDSO 全称就是 Virtual Dynamic Shared Object ,虚拟动态共享对象),并不在文件系统里。至于怎么看这我不太了解,帮你艾特搞 C 的吧 @fefe