linux依赖关系查看命令,Linux下查看依赖关系

我们在开发Linux程序时,经常会遇到查看自己的编译结果是否正常调用外部共享库,至少在编译结果能够查看到这层依赖关系。依赖关系有两种,一种是可执行文件依赖共享库,还有一种是共享库依赖共享库,查看方法如下。

一、可执行文件/二进制文件依赖共享库

ldd命令用来查看可执行文件依赖的共享库文件。

$ ldd --help

Usage: ldd [OPTION]... FILE...

--help print this help and exit

--version print version information and exit

-d, --data-relocs process data relocations

-r, --function-relocs process data and function relocations

-u, --unused print unused direct dependencies

-v, --verbose print all information

示例:

$ ldd helloworld

二、共享库依赖共享库关系

上面的ldd命令无法查看共享库的依赖关系,因为共享库本身并不是可执行文件,我们可以使用

objdump -x libhelloworld.so | grep NEEDED

其中,libhelloworld.so是你的库名称。

附:

readelf命令用于读取ELF Header信息