文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>查找可执行文件使用的动态链接库文件

查找可执行文件使用的动态链接库文件

时间:2009-03-25  来源:blue_stone

在Linux/UNIX中, 大部分程序是动态链接程序, 直到程序在执行的时候, 才会去找对应的库文件, 使用ldd可以查看应用程序使用的库文件:

blueice2:/u01/app/oracle/product/10.2.0/db_3/bin# ldd sqlplus
        linux-gate.so.1 =>  (0xb7fff000)
        libsqlplus.so => /u01/app/oracle/product/10.2.0/db_3/lib/libsqlplus.so (0xb7f4b000)
        libclntsh.so.10.1 => /u01/app/oracle/product/10.2.0/db_3/lib/libclntsh.so.10.1 (0xb71a8000)
        libnnz10.so => /u01/app/oracle/product/10.2.0/db_3/lib/libnnz10.so (0xb6fa3000)
        libdl.so.2 => /lib/i686/cmov/libdl.so.2 (0xb6f84000)
        libm.so.6 => /lib/i686/cmov/libm.so.6 (0xb6f5e000)
        libpthread.so.0 => /lib/i686/cmov/libpthread.so.0 (0xb6f45000)
        libnsl.so.1 => /lib/i686/cmov/libnsl.so.1 (0xb6f2c000)
        libc.so.6 => /lib/i686/cmov/libc.so.6 (0xb6dcb000)
        /lib/ld-linux.so.2 (0xb8000000)


在HPUX中, 可以使用lsatr查看应用程序使用什么路径来寻找库文件.


hbsett1:[/]#chatr /oracle/product/9.2/lib//libclntsh.so.9.0
/oracle/product/9.2/lib//libclntsh.so.9.0:
         64-bit ELF shared library
         shared library dynamic path search:
             LD_LIBRARY_PATH    enabled  first
             SHLIB_PATH         enabled  second
             embedded path      enabled  third  /oracle/product/9.2/lib
         internal name:
             libclntsh.so.9.0
         shared library list:
             libwtc9.so
             librt.so.1
             libnss_dns.so.1
             libdl.so.1
             libm.so.1
             libpthread.so.1
             libCsup.so.1
             libunwind.so.1
         shared library mapped private disabled
         shared vtable support disabled
         explicit unloading enabled
         linkage table protection disabled
         segments:
             index type     address      flags size
                 7 text 4000000000000000 z---c-    D (default)
                 8 data 6000000000000000 ---m--    D (default)
         kernel assisted branch prediction enabled
         lazy swap allocation for dynamic segments disabled
         nulptr dereferences trap enabled
         address space model: default
         caliper dynamic instrumentation disabled

由输出可以看出, 这个库首先会去LD_LIBRARY_PATH环境变量指定的目录中去找需要的动态链接库, 然后去SHLIB_PATH环境变量指定的目录中去找需要的动态链接库, 最后在内嵌的动态链接库目录中去找, 如果在以上目录中都找不到需要的动态链接库, 就报错, 停止执行.

在Linux上可以设置环境变量

export LD_DEBUG=all

然后运行程序, 就可以看到动态链接库加载的过程, 设置LD_DEBUG=help, 可以看到LD_DEBUG的帮助信息.

blueice2:/u01/app/oracle/product/10.2.0/db_3/bin# man ld.so
Valid options for the LD_DEBUG environment variable are:

  libs        display library search paths
  reloc       display relocation processing
  files       display progress for input file
  symbols     display symbol table processing
  bindings    display information about symbol binding
  versions    display version dependencies
  all         all previous options combined
  statistics  display relocation statistics
  unused      determined unused DSOs
  help        display this help message and exit

To direct the debugging output into a file instead of standard output
a filename can be specified using the LD_DEBUG_OUTPUT environment variable.


更多信息请参考man ld.so

相关阅读 更多 +
排行榜 更多 +
日更计划漫画

日更计划漫画

浏览阅读 下载
胶州信息港招聘信息

胶州信息港招聘信息

生活实用 下载
浮生忆玲珑

浮生忆玲珑

角色扮演 下载