库依赖工具 [英] Tool for Library Dependency

查看:164
本文介绍了库依赖工具的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找Unix平台上的tool/command,以检测.so.o文件的library依赖项.

I'm looking for the tool/command on Unix platform to detect the library dependencies of the .so and .o files.

我已经使用过ldd/nm/truss,但是我不知道检测库依赖项的正确方法.

I have already used the ldd/nm/truss, but I don't know the proper approach to detect library dependencies.

推荐答案

这取决于检测库依赖项"的确切含义.

It depends on what exactly is meant by "detect library dependencies".

ldd 命令适用于共享库,而不仅适用于可执行文件.它将显示在构建库时声明的共享库的依赖项:

The ldd command works on shared libraries, not just on executables. It will display the dependencies of a shared library declared when the library was built:

$ ldd /usr/lib/libgtk-3.so
    linux-vdso.so.1 (0x00007ffff8fff000)
    libgdk-3.so.0 => /usr/lib/libgdk-3.so.0 (0x00007f43fcf47000)
    libgmodule-2.0.so.0 => /usr/lib/libgmodule-2.0.so.0 (0x00007f43fcd43000)
    libpangocairo-1.0.so.0 => /usr/lib/libpangocairo-1.0.so.0 (0x00007f43fcb36000)
    libX11.so.6 => /usr/lib/libX11.so.6 (0x00007f43fc7fc000)
...

一个库可以具有未定义的符号,这些符号是通过与其他未声明为依赖项的库链接而获得的.您可以使用 objdump -T

A library can have undefined symbols that are obtained by linking with further libraries not declared as dependencies. You can use objdump -T or nm -D to show the dynamic symbols - undefined symbols (those that should come from other libraries) will show up as *UND*:

$ objdump -T /usr/lib/libgtk-3.so | head

/usr/lib/libgtk-3.so:     file format elf64-x86-64

DYNAMIC SYMBOL TABLE:
0000000000066e38 l    d  .init  0000000000000000              .init
0000000000000000      DF *UND*  0000000000000000              g_param_spec_object
0000000000000000      DF *UND*  0000000000000000              g_utf8_validate
0000000000000000      DF *UND*  0000000000000000              g_date_get_month
0000000000000000      DF *UND*  0000000000000000              g_bookmark_file_get_visited
0000000000000000      DF *UND*  0000000000000000              g_value_get_float

从这些符号名称中,应该可以推断出未声明的库依赖性.

From these symbol names it should be possible to deduce undeclared library dependencies.

使用 pkg-config 或类似配置机制的库有时无法在build-时间,但是将依赖项声明为pkg-config,这依赖于库用户使用该工具来获取依赖项. pkg-config --libs将以编译器可以理解的格式列出依赖性:

Libraries that use pkg-config or similar configuration mechanism sometimes fail to declare their dependencies at build-time, but declare the dependencies to pkg-config, relying on the library users to use the tool to get the dependencies. pkg-config --libs will list the dependencies in the format understood by the compiler:

$ pkg-config --libs gtk+-3.0
-lgtk-3 -lgdk-3 -latk-1.0 -lgio-2.0 -lpangocairo-1.0 -lgdk_pixbuf-2.0 -lcairo-gobject -lpango-1.0 -lcairo -lgobject-2.0 -lglib-2.0  

这篇关于库依赖工具的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆