Linux下的动态库.so

linux 下有动态库和静态库,动态库以.so为扩展名,静态库以.a为扩展名。二者都使用广泛。

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

ldconfig命令:
Usage: ldconfig [OPTION...]
Configure Dynamic Linker Run Time Bindings.


  -c, --format=FORMAT        Format to use: new, old or compat (default)
  -C CACHE                   Use CACHE as cache file
  -f CONF                    Use CONF as configuration file
  -i, --ignore-aux-cache     Ignore auxiliary cache file
  -l                         Manually link individual libraries.
  -n                         Only process directories specified on the command
                             line.  Don't build cache.
  -N                         Don't build cache
  -p, --print-cache          Print cache
  -r ROOT                    Change to and use ROOT as root directory
  -v, --verbose              Generate verbose messages
  -X                         Don't generate links
  -?, --help                 Give this help list
      --usage                Give a short usage message
  -V, --version              Print program version


1.查看一个应用程序使用了哪些动态库
  #ldd /bin/ls
	linux-gate.so.1 =>  (0x00ae8000)
	librt.so.1 => /lib/tls/i686/cmov/librt.so.1 (0x009a5000)
	libselinux.so.1 => /lib/libselinux.so.1 (0x002fb000)
	libacl.so.1 => /lib/libacl.so.1 (0x0049b000)
	libc.so.6 => /lib/tls/i686/cmov/libc.so.6 (0x00543000)
	libpthread.so.0 => /lib/tls/i686/cmov/libpthread.so.0 (0x00b32000)
	/lib/ld-linux.so.2 (0x0088a000)
	libdl.so.2 => /lib/tls/i686/cmov/libdl.so.2 (0x004f7000)
	libattr.so.1 => /lib/libattr.so.1 (0x00a76000)

#ldd /bin/mkdir
	linux-gate.so.1 =>  (0x004d4000)
	libselinux.so.1 => /lib/libselinux.so.1 (0x007be000)
	libc.so.6 => /lib/tls/i686/cmov/libc.so.6 (0x0029b000)
	libdl.so.2 => /lib/tls/i686/cmov/libdl.so.2 (0x00655000)
	/lib/ld-linux.so.2 (0x0076d000)

2.查看应用程序不需要的链接so
  #ldd -u /bin/ls


3.查找环境是否有某些库
   *查找readline库
   #ldconfig -p | grep readline
默认的搜索路径一般是/usr/local/lib,具体可以看/etc/ld.so.conf.d/libc.conf 下的文件;
若要添加其他搜索路径,在libc.conf下添加即可,添加后执行ldconfig;


《linux下so动态库一些不为人知的秘密》这篇文章写得很详细:
http://blog.csdn.net/suwei19870312/article/details/20045281

猜你喜欢

转载自blog.csdn.net/al86866365/article/details/78496235