christinzhm 2013-06-03
一、 动态库配置
1. 修改配置
#cat /etc/ld.so.conf
include ld.so.conf.d/*.conf
# cat /etc/ld.so.conf.d/mysql-x86_64.conf
/usr/lib64/mysql
# file /etc/ld.so.cache ; ldconfig -p 会打印或更新此文件内容
/etc/ld.so.cache: data
2. 通过环境变量LD_LIBRARY_PATH指定动态库搜索路径。
exports $LD_LIBRARY_PATH:/data/mysql5.5/lib/
二、 原理
Linux 动态库的默认搜索路径是/lib和/usr/lib。动态库被创建后,一般都复制到这两个目录中。当程序执行时需要某动态库,并且该动态库还未加载到内存 中,则系统会自动到这两个默认搜索路径中去查找相应的动态库文件,然后加载该文件到内存中,这样程序就可以使用该动态库中的函数,以及该动态库的其它资源 了。在Linux中,动态库的搜索路径除了默认的搜索路径外,还可以通过以下三种方法来指定。
三、命令
1. ldconfig
/sbin/ldconfig - configure dynamic linker run time bindings
DESCRIPTION
ldconfig creates the necessary links and cache to the most recent shared libraries found in the direc-
tories specified on the command line, in the file /etc/ld.so.conf, and in the trusted directories (/lib
and /usr/lib). The cache is used by the run-time linker, ld.so or ld-linux.so. ldconfig checks the
header and filenames of the libraries it encounters when determining which versions should have their
links updated.
#ldconfig -p ;
Print the lists of directories and candidate libraries stored in the current cache.
#ldconfig -v -n /opt/dell/srvadmin/lib64;
Only process directories specified on the command line. Don’t process the trusted directories
(/lib and /usr/lib) nor those specified in /etc/ld.so.conf. Implies -N.
2. ldd
ldd - print shared library dependencies
DESCRIPTION
ldd prints the shared libraries required by each program or shared library specified on the command
line.
#ldd /opt/dell/srvadmin/sbin/dsm_om_connsvcd ; 进程
#ldd -v /opt/dell/srvadmin/sbin/dsm_om_connsvcd
Version information:
/opt/dell/srvadmin/sbin/dsm_om_connsvcd:
libpthread.so.0 (GLIBC_2.2.5) => /lib64/libpthread.so.0
libc.so.6 (GLIBC_2.2.5) => /lib64/libc.so.6
#ldd /usr/lib64/libmenuw.so ; 库文件
3. readelf<br />
命令是一个有很多特性的实用程序,它让您能够解析和读取 ELF 对象。readelf
有一个有趣的用途,就是用来识别对象内可再定位 的项。
elffile... are the object files to be examined. 32-bit and 64-bit ELF files are supported, as are
archives containing ELF files.
#readelf -a /usr/lib64/libmenuw.so
#readelf -r /usr/lib64/libmenuw.so
四、扩展
1. ELF = Executable and Linkable Format,可执行连接格式,是UNIX系统实验室(USL)作为应用程序二进制接口(Application Binary Interface,ABI)而开发和发布的。扩展名为elf。
是不是清楚一点了?
4externintadd(inta,intb);8inti=0;9printf("helloworld!\n");10printf("label_abc=%d\n",&&label_abc);11/