linux - 当我有自定义的 ld-<me>.so.conf 时,ldconfig 也包含默认路径中的库

标签 linux linker

我有交叉编译的库和一个 Linux 加载器。 我在/etc 下放置了一个自定义的 ld-.so.conf ,该conf文件的路径包含所有交叉编译库和加载器。

但是当我运行 ldconfig 时,

ldconfig -C/etc/ld-.so.cache -f/etc/ld-.so.conf

所有系统库及其路径都存在于缓存文件中。 我需要生成的缓存文件仅包含我的交叉编译库。

ldconfig操作的strace如下:

strace /opt/me/ldconfig -C /etc/ld-me.so.cache -f /etc/ld-me.so.conf execve("/opt/me/ldconfig", ["/opt/me/ldc"..., "-C", "/etc/ld-me.so.cache", "-f", "/etc/ld-me.so.conf"], [/* 38 vars */]) = 0

uname({sys="Linux", node="ip-172-31-32-236", ...}) = 0 brk(0)
= 0x10c1000 brk(0x10c2180) = 0x10c2180 arch_prctl(ARCH_SET_FS, 0x10c1860) = 0 brk(0x10e3180)
= 0x10e3180 brk(0x10e4000) = 0x10e4000 open("/usr/lib/locale/locale-archive", O_RDONLY) = 3 fstat(3, {st_mode=S_IFREG|0644, st_size=99154480, ...}) = 0 mmap(NULL, 99154480, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f46155a4000 close(3)
= 0 open("/etc/ld-me.so.conf", O_RDONLY) = 3 fstat(3, {st_mode=S_IFREG|0640, st_size=25, ...}) = 0 mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f46155a3000 read(3, "/opt/me/lib\n", 4096) = 25 stat("/opt/me/lib", {st_mode=S_IFDIR|0750, st_size=4096, ...}) = 0 read(3, "", 4096)
= 0 close(3) = 0 munmap(0x7f46155a3000, 4096) = 0 stat("/lib", {st_mode=S_IFDIR|0555, st_size=4096, ...}) = 0 stat("/lib64", {st_mode=S_IFDIR|0555, st_size=12288, ...}) = 0 stat("/usr/lib", {st_mode=S_IFDIR|0555, st_size=4096, ...}) = 0 stat("/usr/lib64", {st_mode=S_IFDIR|0555, st_size=12288, ...}) = 0 open("/opt/me/lib", O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC) = 3

谁能告诉我为什么要添加系统库?

最佳答案

因为这是 ldconfig 定义的行为:

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.

在编写我剪切粘贴的手册页后,可信目录列表可能已使用 lib64 目录进行了更新。

您可以根据您的conf文件创建一个目录结构,并使用符号链接(symbolic link)或绑定(bind)挂载指向真实目录,然后使用 -r 目录使 ldconfig 基于系统目录的空版本构建。

关于linux - 当我有自定义的 ld-<me>.so.conf 时,ldconfig 也包含默认路径中的库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19657438/

相关文章:

linux - 用参数替换 bash 脚本中的部分命令

linux - 如果 linux 中的任何 PID 超过某个限制,如何发出警报?

用于从动态应用程序创建静态二进制文件的 Linux 工具

c++ - Eclipse/MinGW 不会链接库

C:关于通过使用超过当前 seek_set 的偏移量来使用 lseek 系统调用

linux - Cron 作业在 Homestead 中不起作用

macos - Mac OSX 10.6.7 上的链接错误

linux -/usr/bin/ld : cannot find -lcurl

c++ - 将可执行文件与静态库的完整路径链接起来

linker - 如何以编程方式列出 ELF 共享库符号