Linux系统实用工具——ldd

看你缺点啥——ldd

一、ldd是什么?

ldd(list dynamic dependencies),列出动态库依赖关系。 ldd不是个可执行程式,而只是个shell脚本。 ldd显示可执行模块的dependency的工作原理,其实质是通过ld-linux.so(elf动态库的装载器)来实现的。ld-linux.so模块会先于executable模块程式工作,并获得控制权,因此当上述的那些环境变量被设置时,ld-linux.so选择了显示可执行模块的dependency。

二、ldd能做什么?

用来查看程式运行所需的共享库,常用来解决程式因缺少某个库文件而不能运行的一些问题。

三、ldd怎么使用?

ldd打印命令行中指定的每个程序或共享库所需的共享库。

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

For bug reporting instructions, please see:
<http://www.gnu.org/software/libc/bugs.html>.
OPTIONS
   --version
          Print the version number of ldd.
          
   -v --verbose
          Print all information, including, for example, symbol versioning information.

   -u --unused
          Print unused direct dependencies.  (Since glibc 2.3.4.)

   -d --data-relocs
          Perform relocations and report any missing objects (ELF only).

   -r --function-relocs
          Perform relocations for both data objects and functions, and report any missing objects or functions (ELF only).

   --help Usage information.
$ ldd --version
ldd (GNU libc) 2.12
Copyright (C) 2010 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
由 Roland McGrath 和 Ulrich Drepper 编写。
$ ldd extest.so 
	linux-vdso.so.1 =>  (0x00007fff153ff000)
	libdl.so.2 => /lib64/libdl.so.2 (0x00007f35bb58a000)
	libssl.so.10 => /usr/lib64/libssl.so.10 (0x00007f35bb32f000)
	libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f35bb112000)
	libstdc++.so.6 => /usr/lib64/libstdc++.so.6 (0x00007f35bae0b000)
	libm.so.6 => /lib64/libm.so.6 (0x00007f35baa75000)
	libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007f35ba85e000)
	libc.so.6 => /lib64/libc.so.6 (0x00007f35ba4cb000)
	/lib64/ld-linux-x86-64.so.2 (0x0000003421c00000)
	libgssapi_krb5.so.2 => /lib64/libgssapi_krb5.so.2 (0x00007f35ba287000)
	libkrb5.so.3 => /lib64/libkrb5.so.3 (0x00007f35b9fa0000)
	libcom_err.so.2 => /lib64/libcom_err.so.2 (0x00007f35b9d9c000)
	libk5crypto.so.3 => /lib64/libk5crypto.so.3 (0x00007f35b9b70000)
	libcrypto.so.10 => /usr/lib64/libcrypto.so.10 (0x00007f35b97d5000)
	libz.so.1 => /lib64/libz.so.1 (0x00007f35b95bf000)
	libnsl.so.1 => /lib64/libnsl.so.1 (0x00007f35b93a6000)
	librt.so.1 => /lib64/librt.so.1 (0x00007f35b919d000)
	libkrb5support.so.0 => /lib64/libkrb5support.so.0 (0x00007f35b8f92000)
	libkeyutils.so.1 => /lib64/libkeyutils.so.1 (0x00007f35b8d8f000)
	libresolv.so.2 => /lib64/libresolv.so.2 (0x00007f35b8b74000)
	libselinux.so.1 => /lib64/libselinux.so.1 (0x00007f35b8955000)

$ ldd -u extest.so 
Unused direct dependencies:
	
	/home/tangf//appcom/libZCEFTDAPI.so
	/lib64/libdl.so.2
	/usr/lib64/libssl.so.10
	/lib64/libpthread.so.0
	/lib64/libm.so.6
	/lib64/libgcc_s.so.1

$ ldd -d extest.so 
	linux-vdso.so.1 =>  (0x00007fff153ff000)
	libdl.so.2 => /lib64/libdl.so.2 (0x00007f35bb58a000)
	libssl.so.10 => /usr/lib64/libssl.so.10 (0x00007f35bb32f000)
	libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f35bb112000)
	libstdc++.so.6 => /usr/lib64/libstdc++.so.6 (0x00007f35bae0b000)
	libm.so.6 => /lib64/libm.so.6 (0x00007f35baa75000)
	libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007f35ba85e000)
	libc.so.6 => /lib64/libc.so.6 (0x00007f35ba4cb000)
	/lib64/ld-linux-x86-64.so.2 (0x0000003421c00000)
	libgssapi_krb5.so.2 => /lib64/libgssapi_krb5.so.2 (0x00007f35ba287000)
	libkrb5.so.3 => /lib64/libkrb5.so.3 (0x00007f35b9fa0000)
	libcom_err.so.2 => /lib64/libcom_err.so.2 (0x00007f35b9d9c000)
	libk5crypto.so.3 => /lib64/libk5crypto.so.3 (0x00007f35b9b70000)
	libcrypto.so.10 => /usr/lib64/libcrypto.so.10 (0x00007f35b97d5000)
	libz.so.1 => /lib64/libz.so.1 (0x00007f35b95bf000)
	libnsl.so.1 => /lib64/libnsl.so.1 (0x00007f35b93a6000)
	librt.so.1 => /lib64/librt.so.1 (0x00007f35b919d000)
	libkrb5support.so.0 => /lib64/libkrb5support.so.0 (0x00007f35b8f92000)
	libkeyutils.so.1 => /lib64/libkeyutils.so.1 (0x00007f35b8d8f000)
	libresolv.so.2 => /lib64/libresolv.so.2 (0x00007f35b8b74000)
	libselinux.so.1 => /lib64/libselinux.so.1 (0x00007f35b8955000)

$ ldd -d extest.so | wc -l
23

$ ldd extest.so | wc -l
23

$ ldd -v extest.so | wc -l
161

$ ldd /bin/mv
	linux-vdso.so.1 =>  (0x00007fff0a7ff000)
	libselinux.so.1 => /lib64/libselinux.so.1 (0x0000003423c00000)
	librt.so.1 => /lib64/librt.so.1 (0x0000003423400000)
	libacl.so.1 => /lib64/libacl.so.1 (0x000000342f400000)
	libattr.so.1 => /lib64/libattr.so.1 (0x000000342d000000)
	libc.so.6 => /lib64/libc.so.6 (0x0000003422400000)
	libdl.so.2 => /lib64/libdl.so.2 (0x0000003422000000)
	/lib64/ld-linux-x86-64.so.2 (0x0000003421c00000)
	libpthread.so.0 => /lib64/libpthread.so.0 (0x0000003422800000)

$ ldd /lib64/librt.so.1
	linux-vdso.so.1 =>  (0x00007fff47ccc000)
	libc.so.6 => /lib64/libc.so.6 (0x0000003422400000)
	libpthread.so.0 => /lib64/libpthread.so.0 (0x0000003422800000)
	/lib64/ld-linux-x86-64.so.2 (0x0000003421c00000)
  • 第一列: 程序需要依赖什么库
  • 第二列: 系统提供的与程序需要的库所对应的库
  • 第三列: 库加载的开始地址

通过对比第一列和第二列,我们可以分析程序需要依赖的库和系统实际提供的,是否相匹配。通过观察第三列,我们可以知道在当前库中的符号在对应进程地址空间中的开始位置。

/lib64/libk5crypto.so.3动态库缺失,对比-d、-r选项和默认选项的区别。

$ ldd extest.so 
	linux-vdso.so.1 =>  (0x00007fffb8bff000)
	libZCEFTDAPI.so => /home/tangf//appcom/libZCEFTDAPI.so (0x00007fc58f2f6000)
	libdl.so.2 => /lib64/libdl.so.2 (0x00007fc58f0d3000)
	libssl.so.10 => /usr/lib64/libssl.so.10 (0x00007fc58ee78000)
	libpthread.so.0 => /lib64/libpthread.so.0 (0x00007fc58ec5b000)
	libstdc++.so.6 => /usr/lib64/libstdc++.so.6 (0x00007fc58e954000)
	libf_os.so => /home/tangf//linux.x64/lib/libf_os.so (0x00007fc58e842000)
	libm.so.6 => /lib64/libm.so.6 (0x00007fc58e5be000)
	libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007fc58e3a7000)
	libc.so.6 => /lib64/libc.so.6 (0x00007fc58e014000)
	/lib64/ld-linux-x86-64.so.2 (0x0000003421c00000)
	libgssapi_krb5.so.2 => /lib64/libgssapi_krb5.so.2 (0x00007fc58ddd0000)
	libkrb5.so.3 => /lib64/libkrb5.so.3 (0x00007fc58dae9000)
	libcom_err.so.2 => /lib64/libcom_err.so.2 (0x00007fc58d8e5000)
	libk5crypto.so.3 => not found
	libcrypto.so.10 => /usr/lib64/libcrypto.so.10 (0x00007fc58d54a000)
	libz.so.1 => /lib64/libz.so.1 (0x00007fc58d334000)
	libnsl.so.1 => /lib64/libnsl.so.1 (0x00007fc58d11b000)
	librt.so.1 => /lib64/librt.so.1 (0x00007fc58cf12000)
	libk5crypto.so.3 => not found
	libkrb5support.so.0 => /lib64/libkrb5support.so.0 (0x00007fc58cd07000)
	libkeyutils.so.1 => /lib64/libkeyutils.so.1 (0x00007fc58cb03000)
	libresolv.so.2 => /lib64/libresolv.so.2 (0x00007fc58c8e9000)
	libk5crypto.so.3 => not found
	libselinux.so.1 => /lib64/libselinux.so.1 (0x00007fc58c6c9000)

$ ldd -d extest.so 
	linux-vdso.so.1 =>  (0x00007fffb93d7000)
	libdl.so.2 => /lib64/libdl.so.2 (0x00007fb45c4c0000)
	libssl.so.10 => /usr/lib64/libssl.so.10 (0x00007fb45c265000)
	libpthread.so.0 => /lib64/libpthread.so.0 (0x00007fb45c048000)
	libstdc++.so.6 => /usr/lib64/libstdc++.so.6 (0x00007fb45bd41000)
	libm.so.6 => /lib64/libm.so.6 (0x00007fb45b9ab000)
	libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007fb45b794000)
	libc.so.6 => /lib64/libc.so.6 (0x00007fb45b401000)
	/lib64/ld-linux-x86-64.so.2 (0x0000003421c00000)
	libgssapi_krb5.so.2 => /lib64/libgssapi_krb5.so.2 (0x00007fb45b1bd000)
	libkrb5.so.3 => /lib64/libkrb5.so.3 (0x00007fb45aed6000)
	libcom_err.so.2 => /lib64/libcom_err.so.2 (0x00007fb45acd2000)
	libk5crypto.so.3 => not found
	libcrypto.so.10 => /usr/lib64/libcrypto.so.10 (0x00007fb45a937000)
	libz.so.1 => /lib64/libz.so.1 (0x00007fb45a721000)
	libnsl.so.1 => /lib64/libnsl.so.1 (0x00007fb45a508000)
	librt.so.1 => /lib64/librt.so.1 (0x00007fb45a2ff000)
	libk5crypto.so.3 => not found
	libkrb5support.so.0 => /lib64/libkrb5support.so.0 (0x00007fb45a0f4000)
	libkeyutils.so.1 => /lib64/libkeyutils.so.1 (0x00007fb459ef0000)
	libresolv.so.2 => /lib64/libresolv.so.2 (0x00007fb459cd6000)
	libk5crypto.so.3 => not found
	libselinux.so.1 => /lib64/libselinux.so.1 (0x00007fb459ab6000)
undefined symbol: krb5int_arcfour_gsscrypt, version k5crypto_3_MIT	(/lib64/libkrb5.so.3)
undefined symbol: krb5int_c_mandatory_cksumtype, version k5crypto_3_MIT	(/lib64/libkrb5.so.3)

$ ldd -r extest.so 
	linux-vdso.so.1 =>  (0x00007fffa31ff000)
	libdl.so.2 => /lib64/libdl.so.2 (0x00007fbc3ec42000)
	libssl.so.10 => /usr/lib64/libssl.so.10 (0x00007fbc3e9e7000)
	libpthread.so.0 => /lib64/libpthread.so.0 (0x00007fbc3e7ca000)
	libstdc++.so.6 => /usr/lib64/libstdc++.so.6 (0x00007fbc3e4c3000)
	libm.so.6 => /lib64/libm.so.6 (0x00007fbc3e12d000)
	libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007fbc3df16000)
	libc.so.6 => /lib64/libc.so.6 (0x00007fbc3db83000)
	/lib64/ld-linux-x86-64.so.2 (0x0000003421c00000)
	libgssapi_krb5.so.2 => /lib64/libgssapi_krb5.so.2 (0x00007fbc3d93f000)
	libkrb5.so.3 => /lib64/libkrb5.so.3 (0x00007fbc3d658000)
	libcom_err.so.2 => /lib64/libcom_err.so.2 (0x00007fbc3d454000)
	libk5crypto.so.3 => not found
	libcrypto.so.10 => /usr/lib64/libcrypto.so.10 (0x00007fbc3d0b9000)
	libz.so.1 => /lib64/libz.so.1 (0x00007fbc3cea3000)
	libnsl.so.1 => /lib64/libnsl.so.1 (0x00007fbc3cc8a000)
	librt.so.1 => /lib64/librt.so.1 (0x00007fbc3ca81000)
	libk5crypto.so.3 => not found
	libkrb5support.so.0 => /lib64/libkrb5support.so.0 (0x00007fbc3c876000)
	libkeyutils.so.1 => /lib64/libkeyutils.so.1 (0x00007fbc3c672000)
	libresolv.so.2 => /lib64/libresolv.so.2 (0x00007fbc3c458000)
	libk5crypto.so.3 => not found
	libselinux.so.1 => /lib64/libselinux.so.1 (0x00007fbc3c238000)
undefined symbol: krb5int_arcfour_gsscrypt, version k5crypto_3_MIT	(/lib64/libkrb5.so.3)
undefined symbol: krb5int_c_mandatory_cksumtype, version k5crypto_3_MIT	(/lib64/libkrb5.so.3)
undefined symbol: krb5_k_encrypt, version k5crypto_3_MIT	(/lib64/libkrb5.so.3)
undefined symbol: krb5_c_string_to_key, version k5crypto_3_MIT	(/lib64/libkrb5.so.3)
undefined symbol: krb5_c_block_size, version k5crypto_3_MIT	(/lib64/libkrb5.so.3)
undefined symbol: krb5int_c_mandatory_cksumtype, version k5crypto_3_MIT	(/lib64/libkrb5.so.3)
undefined symbol: krb5int_c_copy_keyblock_contents, version k5crypto_3_MIT	(/lib64/libkrb5.so.3)
undefined symbol: krb5_k_reference_key, version k5crypto_3_MIT	(/lib64/libkrb5.so.3)
undefined symbol: krb5int_c_combine_keys, version k5crypto_3_MIT	(/lib64/libkrb5.so.3)
undefined symbol: krb5_k_free_key, version k5crypto_3_MIT	(/lib64/libkrb5.so.3)
undefined symbol: krb5_c_enctype_compare, version k5crypto_3_MIT	(/lib64/libkrb5.so.3)
undefined symbol: krb5_string_to_enctype, version k5crypto_3_MIT	(/lib64/libkrb5.so.3)
undefined symbol: krb5_c_make_checksum, version k5crypto_3_MIT	(/lib64/libkrb5.so.3)
undefined symbol: krb5_k_decrypt, version k5crypto_3_MIT	(/lib64/libkrb5.so.3)
undefined symbol: krb5_c_fx_cf2_simple, version k5crypto_3_MIT	(/lib64/libkrb5.so.3)
undefined symbol: krb5_c_random_add_entropy, version k5crypto_3_MIT	(/lib64/libkrb5.so.3)
undefined symbol: krb5_k_create_key, version k5crypto_3_MIT	(/lib64/libkrb5.so.3)
undefined symbol: krb5int_c_init_keyblock, version k5crypto_3_MIT	(/lib64/libkrb5.so.3)
undefined symbol: krb5int_c_free_keyblock, version k5crypto_3_MIT	(/lib64/libkrb5.so.3)
undefined symbol: krb5int_c_weak_enctype, version k5crypto_3_MIT	(/lib64/libkrb5.so.3)
undefined symbol: krb5_c_checksum_length, version k5crypto_3_MIT	(/lib64/libkrb5.so.3)
undefined symbol: krb5_c_random_make_octets, version k5crypto_3_MIT	(/lib64/libkrb5.so.3)
undefined symbol: krb5_k_key_keyblock, version k5crypto_3_MIT	(/lib64/libkrb5.so.3)
undefined symbol: krb5_c_valid_cksumtype, version k5crypto_3_MIT	(/lib64/libkrb5.so.3)
undefined symbol: krb5_k_key_enctype, version k5crypto_3_MIT	(/lib64/libkrb5.so.3)
undefined symbol: krb5_c_encrypt_length, version k5crypto_3_MIT	(/lib64/libkrb5.so.3)
undefined symbol: krb5_c_string_to_key_with_params, version k5crypto_3_MIT	(/lib64/libkrb5.so.3)
undefined symbol: krb5int_c_copy_keyblock, version k5crypto_3_MIT	(/lib64/libkrb5.so.3)
undefined symbol: krb5_c_verify_checksum, version k5crypto_3_MIT	(/lib64/libkrb5.so.3)
undefined symbol: krb5_c_encrypt, version k5crypto_3_MIT	(/lib64/libkrb5.so.3)
undefined symbol: krb5_c_is_coll_proof_cksum, version k5crypto_3_MIT	(/lib64/libkrb5.so.3)
undefined symbol: krb5_enctype_to_string, version k5crypto_3_MIT	(/lib64/libkrb5.so.3)
undefined symbol: krb5_c_valid_enctype, version k5crypto_3_MIT	(/lib64/libkrb5.so.3)
undefined symbol: krb5_c_make_checksum_iov, version k5crypto_3_MIT	(/lib64/libkrb5.so.3)
undefined symbol: krb5_k_make_checksum, version k5crypto_3_MIT	(/lib64/libkrb5.so.3)
undefined symbol: krb5_k_verify_checksum, version k5crypto_3_MIT	(/lib64/libkrb5.so.3)
undefined symbol: krb5_c_is_keyed_cksum, version k5crypto_3_MIT	(/lib64/libkrb5.so.3)
undefined symbol: krb5_c_make_random_key, version k5crypto_3_MIT	(/lib64/libkrb5.so.3)
undefined symbol: krb5_enctype_to_name, version k5crypto_3_MIT	(/lib64/libkrb5.so.3)
undefined symbol: krb5_c_random_os_entropy, version k5crypto_3_MIT	(/lib64/libkrb5.so.3)
undefined symbol: krb5_c_keyed_checksum_types, version k5crypto_3_MIT	(/lib64/libkrb5.so.3)
undefined symbol: krb5int_c_free_keyblock_contents, version k5crypto_3_MIT	(/lib64/libkrb5.so.3)
undefined symbol: krb5_free_cksumtypes, version k5crypto_3_MIT	(/lib64/libkrb5.so.3)
undefined symbol: krb5_c_decrypt, version k5crypto_3_MIT	(/lib64/libkrb5.so.3)
undefined symbol: krb5_c_padding_length, version k5crypto_3_MIT	(/lib64/libgssapi_krb5.so.2)
undefined symbol: krb5_k_encrypt, version k5crypto_3_MIT	(/lib64/libgssapi_krb5.so.2)
undefined symbol: krb5_c_block_size, version k5crypto_3_MIT	(/lib64/libgssapi_krb5.so.2)
undefined symbol: krb5int_c_mandatory_cksumtype, version k5crypto_3_MIT	(/lib64/libgssapi_krb5.so.2)
undefined symbol: krb5_k_free_key, version k5crypto_3_MIT	(/lib64/libgssapi_krb5.so.2)
undefined symbol: krb5_c_make_checksum, version k5crypto_3_MIT	(/lib64/libgssapi_krb5.so.2)
undefined symbol: krb5_k_decrypt, version k5crypto_3_MIT	(/lib64/libgssapi_krb5.so.2)
undefined symbol: krb5_k_make_checksum_iov, version k5crypto_3_MIT	(/lib64/libgssapi_krb5.so.2)
undefined symbol: krb5_k_create_key, version k5crypto_3_MIT	(/lib64/libgssapi_krb5.so.2)
undefined symbol: krb5_c_checksum_length, version k5crypto_3_MIT	(/lib64/libgssapi_krb5.so.2)
undefined symbol: krb5_c_crypto_length, version k5crypto_3_MIT	(/lib64/libgssapi_krb5.so.2)
undefined symbol: krb5_c_random_make_octets, version k5crypto_3_MIT	(/lib64/libgssapi_krb5.so.2)
undefined symbol: krb5_k_key_keyblock, version k5crypto_3_MIT	(/lib64/libgssapi_krb5.so.2)
undefined symbol: krb5_k_key_enctype, version k5crypto_3_MIT	(/lib64/libgssapi_krb5.so.2)
undefined symbol: krb5_c_prf_length, version k5crypto_3_MIT	(/lib64/libgssapi_krb5.so.2)
undefined symbol: krb5int_arcfour_gsscrypt, version k5crypto_3_MIT	(/lib64/libgssapi_krb5.so.2)
undefined symbol: krb5_encrypt_size, version k5crypto_3_MIT	(/lib64/libgssapi_krb5.so.2)
undefined symbol: krb5_c_valid_enctype, version k5crypto_3_MIT	(/lib64/libgssapi_krb5.so.2)
undefined symbol: krb5_k_prf, version k5crypto_3_MIT	(/lib64/libgssapi_krb5.so.2)
undefined symbol: krb5_k_make_checksum, version k5crypto_3_MIT	(/lib64/libgssapi_krb5.so.2)
undefined symbol: krb5_k_verify_checksum, version k5crypto_3_MIT	(/lib64/libgssapi_krb5.so.2)
undefined symbol: krb5_k_verify_checksum_iov, version k5crypto_3_MIT	(/lib64/libgssapi_krb5.so.2)
undefined symbol: krb5_k_encrypt_iov, version k5crypto_3_MIT	(/lib64/libgssapi_krb5.so.2)
undefined symbol: krb5_k_decrypt_iov, version k5crypto_3_MIT	(/lib64/libgssapi_krb5.so.2)
undefined symbol: valid_cksumtype, version k5crypto_3_MIT	(/usr/lib64/libssl.so.10)
undefined symbol: krb5_checksum_size, version k5crypto_3_MIT	(/usr/lib64/libssl.so.10)

$ ldd extest.so | wc -l
25

$ ldd -d extest.so | wc -l
undefined symbol: krb5int_arcfour_gsscrypt, version k5crypto_3_MIT	(/lib64/libkrb5.so.3)
undefined symbol: krb5int_c_mandatory_cksumtype, version k5crypto_3_MIT	(/lib64/libkrb5.so.3)
25

$ ldd -r extest.so | wc -l
undefined symbol: krb5int_arcfour_gsscrypt, version k5crypto_3_MIT	(/lib64/libkrb5.so.3)
undefined symbol: krb5int_c_mandatory_cksumtype, version k5crypto_3_MIT	(/lib64/libkrb5.so.3)
undefined symbol: krb5_k_encrypt, version k5crypto_3_MIT	(/lib64/libkrb5.so.3)
undefined symbol: krb5_c_string_to_key, version k5crypto_3_MIT	(/lib64/libkrb5.so.3)
undefined symbol: krb5_c_block_size, version k5crypto_3_MIT	(/lib64/libkrb5.so.3)
undefined symbol: krb5int_c_mandatory_cksumtype, version k5crypto_3_MIT	(/lib64/libkrb5.so.3)
undefined symbol: krb5int_c_copy_keyblock_contents, version k5crypto_3_MIT	(/lib64/libkrb5.so.3)
undefined symbol: krb5_k_reference_key, version k5crypto_3_MIT	(/lib64/libkrb5.so.3)
undefined symbol: krb5int_c_combine_keys, version k5crypto_3_MIT	(/lib64/libkrb5.so.3)
undefined symbol: krb5_k_free_key, version k5crypto_3_MIT	(/lib64/libkrb5.so.3)
undefined symbol: krb5_c_enctype_compare, version k5crypto_3_MIT	(/lib64/libkrb5.so.3)
undefined symbol: krb5_string_to_enctype, version k5crypto_3_MIT	(/lib64/libkrb5.so.3)
undefined symbol: krb5_c_make_checksum, version k5crypto_3_MIT	(/lib64/libkrb5.so.3)
undefined symbol: krb5_k_decrypt, version k5crypto_3_MIT	(/lib64/libkrb5.so.3)
undefined symbol: krb5_c_fx_cf2_simple, version k5crypto_3_MIT	(/lib64/libkrb5.so.3)
undefined symbol: krb5_c_random_add_entropy, version k5crypto_3_MIT	(/lib64/libkrb5.so.3)
undefined symbol: krb5_k_create_key, version k5crypto_3_MIT	(/lib64/libkrb5.so.3)
undefined symbol: krb5int_c_init_keyblock, version k5crypto_3_MIT	(/lib64/libkrb5.so.3)
undefined symbol: krb5int_c_free_keyblock, version k5crypto_3_MIT	(/lib64/libkrb5.so.3)
undefined symbol: krb5int_c_weak_enctype, version k5crypto_3_MIT	(/lib64/libkrb5.so.3)
undefined symbol: krb5_c_checksum_length, version k5crypto_3_MIT	(/lib64/libkrb5.so.3)
undefined symbol: krb5_c_random_make_octets, version k5crypto_3_MIT	(/lib64/libkrb5.so.3)
undefined symbol: krb5_k_key_keyblock, version k5crypto_3_MIT	(/lib64/libkrb5.so.3)
undefined symbol: krb5_c_valid_cksumtype, version k5crypto_3_MIT	(/lib64/libkrb5.so.3)
undefined symbol: krb5_k_key_enctype, version k5crypto_3_MIT	(/lib64/libkrb5.so.3)
undefined symbol: krb5_c_encrypt_length, version k5crypto_3_MIT	(/lib64/libkrb5.so.3)
undefined symbol: krb5_c_string_to_key_with_params, version k5crypto_3_MIT	(/lib64/libkrb5.so.3)
undefined symbol: krb5int_c_copy_keyblock, version k5crypto_3_MIT	(/lib64/libkrb5.so.3)
undefined symbol: krb5_c_verify_checksum, version k5crypto_3_MIT	(/lib64/libkrb5.so.3)
undefined symbol: krb5_c_encrypt, version k5crypto_3_MIT	(/lib64/libkrb5.so.3)
undefined symbol: krb5_c_is_coll_proof_cksum, version k5crypto_3_MIT	(/lib64/libkrb5.so.3)
undefined symbol: krb5_enctype_to_string, version k5crypto_3_MIT	(/lib64/libkrb5.so.3)
undefined symbol: krb5_c_valid_enctype, version k5crypto_3_MIT	(/lib64/libkrb5.so.3)
undefined symbol: krb5_c_make_checksum_iov, version k5crypto_3_MIT	(/lib64/libkrb5.so.3)
undefined symbol: krb5_k_make_checksum, version k5crypto_3_MIT	(/lib64/libkrb5.so.3)
undefined symbol: krb5_k_verify_checksum, version k5crypto_3_MIT	(/lib64/libkrb5.so.3)
undefined symbol: krb5_c_is_keyed_cksum, version k5crypto_3_MIT	(/lib64/libkrb5.so.3)
undefined symbol: krb5_c_make_random_key, version k5crypto_3_MIT	(/lib64/libkrb5.so.3)
undefined symbol: krb5_enctype_to_name, version k5crypto_3_MIT	(/lib64/libkrb5.so.3)
undefined symbol: krb5_c_random_os_entropy, version k5crypto_3_MIT	(/lib64/libkrb5.so.3)
undefined symbol: krb5_c_keyed_checksum_types, version k5crypto_3_MIT	(/lib64/libkrb5.so.3)
undefined symbol: krb5int_c_free_keyblock_contents, version k5crypto_3_MIT	(/lib64/libkrb5.so.3)
undefined symbol: krb5_free_cksumtypes, version k5crypto_3_MIT	(/lib64/libkrb5.so.3)
undefined symbol: krb5_c_decrypt, version k5crypto_3_MIT	(/lib64/libkrb5.so.3)
undefined symbol: krb5_c_padding_length, version k5crypto_3_MIT	(/lib64/libgssapi_krb5.so.2)
undefined symbol: krb5_k_encrypt, version k5crypto_3_MIT	(/lib64/libgssapi_krb5.so.2)
undefined symbol: krb5_c_block_size, version k5crypto_3_MIT	(/lib64/libgssapi_krb5.so.2)
undefined symbol: krb5int_c_mandatory_cksumtype, version k5crypto_3_MIT	(/lib64/libgssapi_krb5.so.2)
undefined symbol: krb5_k_free_key, version k5crypto_3_MIT	(/lib64/libgssapi_krb5.so.2)
undefined symbol: krb5_c_make_checksum, version k5crypto_3_MIT	(/lib64/libgssapi_krb5.so.2)
undefined symbol: krb5_k_decrypt, version k5crypto_3_MIT	(/lib64/libgssapi_krb5.so.2)
undefined symbol: krb5_k_make_checksum_iov, version k5crypto_3_MIT	(/lib64/libgssapi_krb5.so.2)
undefined symbol: krb5_k_create_key, version k5crypto_3_MIT	(/lib64/libgssapi_krb5.so.2)
undefined symbol: krb5_c_checksum_length, version k5crypto_3_MIT	(/lib64/libgssapi_krb5.so.2)
undefined symbol: krb5_c_crypto_length, version k5crypto_3_MIT	(/lib64/libgssapi_krb5.so.2)
undefined symbol: krb5_c_random_make_octets, version k5crypto_3_MIT	(/lib64/libgssapi_krb5.so.2)
undefined symbol: krb5_k_key_keyblock, version k5crypto_3_MIT	(/lib64/libgssapi_krb5.so.2)
undefined symbol: krb5_k_key_enctype, version k5crypto_3_MIT	(/lib64/libgssapi_krb5.so.2)
undefined symbol: krb5_c_prf_length, version k5crypto_3_MIT	(/lib64/libgssapi_krb5.so.2)
undefined symbol: krb5int_arcfour_gsscrypt, version k5crypto_3_MIT	(/lib64/libgssapi_krb5.so.2)
undefined symbol: krb5_encrypt_size, version k5crypto_3_MIT	(/lib64/libgssapi_krb5.so.2)
undefined symbol: krb5_c_valid_enctype, version k5crypto_3_MIT	(/lib64/libgssapi_krb5.so.2)
undefined symbol: krb5_k_prf, version k5crypto_3_MIT	(/lib64/libgssapi_krb5.so.2)
undefined symbol: krb5_k_make_checksum, version k5crypto_3_MIT	(/lib64/libgssapi_krb5.so.2)
undefined symbol: krb5_k_verify_checksum, version k5crypto_3_MIT	(/lib64/libgssapi_krb5.so.2)
undefined symbol: krb5_k_verify_checksum_iov, version k5crypto_3_MIT	(/lib64/libgssapi_krb5.so.2)
undefined symbol: krb5_k_encrypt_iov, version k5crypto_3_MIT	(/lib64/libgssapi_krb5.so.2)
undefined symbol: krb5_k_decrypt_iov, version k5crypto_3_MIT	(/lib64/libgssapi_krb5.so.2)
undefined symbol: valid_cksumtype, version k5crypto_3_MIT	(/usr/lib64/libssl.so.10)
undefined symbol: krb5_checksum_size, version k5crypto_3_MIT	(/usr/lib64/libssl.so.10)
25

ldd可用于查看ELF格式动态可执行文件的依赖关系,如:动态库、可执行程。不能查看其它文件,如:静态库。

$ file test.a 
test.a: current ar archive

$ file extest.so 
extest.so: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, not stripped

$ file recv
recv: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.18, not stripped

$ ldd test.a 
	不是动态可执行文件

$ ldd extest.so 
	linux-vdso.so.1 =>  (0x00007fff89fff000)
	libdl.so.2 => /lib64/libdl.so.2 (0x00007fa3485d0000)
	libssl.so.10 => /usr/lib64/libssl.so.10 (0x00007fa348375000)
	libpthread.so.0 => /lib64/libpthread.so.0 (0x00007fa348158000)
	libstdc++.so.6 => /usr/lib64/libstdc++.so.6 (0x00007fa347e51000)
	libm.so.6 => /lib64/libm.so.6 (0x00007fa347abb000)
	libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007fa3478a4000)
	libc.so.6 => /lib64/libc.so.6 (0x00007fa347511000)
	/lib64/ld-linux-x86-64.so.2 (0x0000003421c00000)
	libgssapi_krb5.so.2 => /lib64/libgssapi_krb5.so.2 (0x00007fa3472cd000)
	libkrb5.so.3 => /lib64/libkrb5.so.3 (0x00007fa346fe6000)
	libcom_err.so.2 => /lib64/libcom_err.so.2 (0x00007fa346de2000)
	libk5crypto.so.3 => /lib64/libk5crypto.so.3 (0x00007fa346bb6000)
	libcrypto.so.10 => /usr/lib64/libcrypto.so.10 (0x00007fa34681b000)
	libz.so.1 => /lib64/libz.so.1 (0x00007fa346605000)
	libnsl.so.1 => /lib64/libnsl.so.1 (0x00007fa3463ec000)
	librt.so.1 => /lib64/librt.so.1 (0x00007fa3461e3000)
	libkrb5support.so.0 => /lib64/libkrb5support.so.0 (0x00007fa345fd8000)
	libkeyutils.so.1 => /lib64/libkeyutils.so.1 (0x00007fa345dd5000)
	libresolv.so.2 => /lib64/libresolv.so.2 (0x00007fa345bba000)
	libselinux.so.1 => /lib64/libselinux.so.1 (0x00007fa34599b000)

$ ll recv*
-rw-rw-r--. 1 tangf tangf 2949 2月  26 2019 recv.cpp
-rwxrwxr-x. 1 tangf tangf 9630 2月  26 2019 recv

$ ldd recv.cpp 
ldd: 警告: 你没有执行权限  `./recv.cpp'
	不是动态可执行文件

$ ldd recv
	linux-vdso.so.1 =>  (0x00007fff07dff000)
	libstdc++.so.6 => /usr/lib64/libstdc++.so.6 (0x0000003429000000)
	libm.so.6 => /lib64/libm.so.6 (0x0000003423000000)
	libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x0000003427400000)
	libc.so.6 => /lib64/libc.so.6 (0x0000003422400000)
	/lib64/ld-linux-x86-64.so.2 (0x0000003421c00000)

如果依赖的某个库找不到,通过这个命令可以迅速定位问题所在。

# ll /lib64/libk5crypto.so.3
lrwxrwxrwx. 1 root root 18 Aug  8  2018 /lib64/libk5crypto.so.3 -> libk5crypto.so.3.1

# mv /lib64/libk5crypto.so.3 /lib64/libk5crypto.so.4

# ll /lib64/libk5crypto.so.3
ls: cannot access /lib64/libk5crypto.so.3: No such file or directory

$ ldd extest.so | grep --color=auto libk5crypto.so.3
	libk5crypto.so.3 => not found
	libk5crypto.so.3 => not found
	libk5crypto.so.3 => not found

$ ldd extest.so | grep --color=auto "not found"
	libk5crypto.so.3 => not found
	libk5crypto.so.3 => not found
	libk5crypto.so.3 => not found

# mv /lib64/libk5crypto.so.4 /lib64/libk5crypto.so.3
# ll /lib64/libk5crypto.so.3
lrwxrwxrwx. 1 root root 18 Aug  8  2018 /lib64/libk5crypto.so.3 -> libk5crypto.so.3.1

$ ldd extest.so | grep --color=auto libk5crypto.so.3
	libk5crypto.so.3 => /lib64/libk5crypto.so.3 (0x00007f28c90d0000)
	
$  ldd extest.so | grep --color=auto "not found" | wc -l
0

你可能感兴趣的:(Linux)