【问题标题】:rpm: list unnecessary dependencies like dpkg-shlibdeps does?rpm:列出不必要的依赖项,例如 dpkg-shlibdeps 吗?
【发布时间】:2023-09-25 09:59:01
【问题描述】:

在构建 .deb 包时,dpkg-shlibdeps 被(或可以)调用以自动添加对包使用的库的依赖项。

它会产生有用的输出,例如:

dpkg-shlibdeps: warning: package could avoid a useless dependency if ./foo.so were not linked against libboost_regex.so.1.62.0 (they use none of the library's symbols)

rpm 是否有等效的功能?还是预先存在的平台中立工具?

【问题讨论】:

  • dpkg-shlibdeps 里面用来检测这个的魔法是什么?也许值得将其引入一个平台中立的工具,然后可以由 RPM 调用?

标签: rpm rpmbuild dpkg


【解决方案1】:

是和不是:)

rpmbuild 自动添加 .so 依赖。

您可以检查rpm -qR bash 是否列出了此要求:

...
libc.so.6(GLIBC_2.11)(64bit)
libc.so.6(GLIBC_2.14)(64bit)
libc.so.6(GLIBC_2.15)(64bit)
...

但正如您在来源中看到的那样:https://src.fedoraproject.org/rpms/bash/blob/master/f/bash.spec 没有这样的行:

Requires: libc.so.6(GLIBC_2.11)(64bit)

这适用于 .so 库、Perl 模块以及最近在 Fedora 中的 Python 模块。任何其他库都必须手动添加到规范文件中。

但是,这些依赖关系是在链接库上计算的,如果您链​​接到该库,但不使用该库中的任何符号,那么恐怕 RPM 世界没有任何实用程序来检测这种无用的依赖关系。

【讨论】:

    【解决方案2】:

    我有一个部分答案。

    RPM 不直接支持这一点。 RPM 通过脚本find-requiresfind-provides(通常在/usr/lib/rpm 中)查找包需要和提供的内容。

    这些运行如下:

    >find . | /usr/lib/rpm/find-provides
    libfoobar.so.1()(64bit)
    
    >find . | /usr/lib/rpm/find-requires
    libasound.so.2()(64bit)
    libboost_atomic-mt.so.1.53.0()(64bit)
    libboost_chrono-mt.so.1.53.0()(64bit)
    libboost_date_time-mt.so.1.53.0()(64bit)
    libboost_filesystem-mt.so.1.53.0()(64bit)
    libboost_regex-mt.so.1.53.0()(64bit)
    libboost_system-mt.so.1.53.0()(64bit)
    libboost_thread-mt.so.1.53.0()(64bit)
    libboost_unit_test_framework-mt.so.1.53.0()(64bit)
    libc.so.6()(64bit)
    libc.so.6(GLIBC_2.14)(64bit)
    

    还有一个编译程序 /usr/lib/rpm/elfdeps 以相同的方式工作。 rpmbuild 似乎使用它而不是脚本。

    http://ftp.rpm.org/max-rpm/s1-rpm-depend-auto-depend.html(注意真正的脚本和那里的例子不太一样)。

    剩下的问题是 dpkg-shlibdeps 是怎么做的? 如果没有人先到,我会在有时间查看时添加。

    【讨论】:

    • 您在问题中链接到的手册页详细解释了 dpkg-shlibdeps 的机制。