1. readelf
该指令可以查看当前 elf 文件的依赖。
比如这样:
readelf -d libtinyalsa.a
File: libtinyalsa.a(limits.o)
File: libtinyalsa.a(mixer.o)
File: libtinyalsa.a(pcm.o)
表示这个 .a 依赖于是哪几个 .o 文件
再比如这样:
$ readelf -d libtinyalsa.so
Dynamic section at offset 0x6d24 contains 26 entries:
Tag Type Name/Value
0x00000001 (NEEDED) Shared library: [libgcc_s.so.1]
0x00000001 (NEEDED) Shared library: [libc.so.6]
0x0000000e (SONAME) Library soname: [libtinyalsa.so.1]
0x0000000c (INIT) 0x1540
0x0000000d (FINI) 0x6484
0x00000019 (INIT_ARRAY) 0xed18
0x0000001b (INIT_ARRAYSZ) 4 (bytes)
0x0000001a (FINI_ARRAY) 0xed1c
0x0000001c (FINI_ARRAYSZ) 4 (bytes)
0x00000004 (HASH) 0xd4
0x00000005 (STRTAB) 0xb70
0x00000006 (SYMTAB) 0x430
0x0000000a (STRSZ) 1735 (bytes)
0x0000000b (SYMENT) 16 (bytes)
0x00000003 (PLTGOT) 0xee14
0x00000002 (PLTRELSZ) 392 (bytes)
0x00000014 (PLTREL) REL
0x00000017 (JMPREL) 0x13b8
0x00000011 (REL) 0x1370
0x00000012 (RELSZ) 72 (bytes)
0x00000013 (RELENT) 8 (bytes)
0x6ffffffe (VERNEED) 0x1320
0x6fffffff (VERNEEDNUM) 2
0x6ffffff0 (VERSYM) 0x1238
0x6ffffffa (RELCOUNT) 3
0x00000000 (NULL) 0x0
从上面可以看出,该 .so 文件依赖于哪几个 so 库文件,这样有利于处理库依赖情况。比如要在设备里完成该该 so 的调用,就必须在该设备的某个指定目录 /lib 或者 /system/lib 下存在这几个库,不然就会出现 no such file 情况。