好记性不如铅笔头

linux, 编程

Linux常用命令备份:ldconfig

以下内容参考【 http://www.cppblog.com/aaxron/archive/2012/08/02/185995.html 】,有删改。

 ldconfig主要是在默认搜寻目录(/lib和/usr/lib)以及动态库配置文件/etc/ld.so.conf内所列的目录下,搜索出可共享的动态链接库(格式如前介绍,lib*.so*),进而创建出动态装入程序(ld.so)所需的连接和缓存文件.缓存文件默认为 /etc/ld.so.cache,此文件保存已排好序的动态链接库名字列表.
linux下的共享库机制采用了类似于高速缓存的机制,将库信息保存在/etc/ld.so.cache里边。
程序连接的时候首先从这个文件里边查找,然后再到ld.so.conf的路径里边去详细找。
这就是为什么修改了ld.so.conf要重新运行一下ldconfig的原因
补充一点,ldconfig在/sbin里面。
ldconfig几个需要注意的地方
1. 往/lib和/usr/lib里面加东西,是不用修改/etc/ld.so.conf的,但是完了之后要调一下ldconfig,不然这个library会找不到
2. 想往上面两个目录以外加东西的时候,一定要修改/etc/ld.so.conf,然后再调用ldconfig,不然也会找不到
比如安装了一个mysql到/usr/local/mysql,mysql有一大堆library在/usr/local/mysql/lib下面,这时就需要在/etc/ld.so.conf下面加一行/usr/local/mysql/lib,保存过后ldconfig一下,新的library才能在程序运行时被找到。
3. 如果想在这两个目录以外放lib,但是又不想在/etc/ld.so.conf中加东西(或者是没有权限加东西)。那也可以,就是export一个全局变量LD_LIBRARY_PATH,然后运行程序的时候就会去这个目录中找library。一般来讲这只是一种临时的解决方案,在没有权限或临时需要的时候使用。
4. ldconfig做的这些东西都与运行程序时有关,跟编译时一点关系都没有。编译的时候还是该加-L就得加,不要混淆了。
5. 总之,就是不管做了什么关于library的变动后,最好都ldconfig一下,不然会出现一些意想不到的结果。不会花太多的时间,但是会省很多的事。

Linux对于ldconfig的命令的用法介绍:

cstriker1407@cstriker1407-x64:~$ ldconfig --help
用法: ldconfig.real [选项...]
Configure Dynamic Linker Run Time Bindings.

  -c, --format=FORMAT        采用的格式:新、旧或兼容(默认)
  -C CACHE                   将 CACHE 用作缓冲区文件
  -f CONF                    将 CONF 用作配置文件
  -i, --ignore-aux-cache     忽略辅助缓存文件
  -l                         手工连接独立的库。
  -n
                             只在命令行中给出了进程目录。未创建缓冲区。
  -N                         不要创建缓冲区
  -p, --print-cache          打印缓冲区
  -r ROOT                    进入 ROOT 目录并将其作为根目录
  -v, --verbose              生成详细消息
  -X                         不要生成连接
  -?, --help                 给出该系统求助列表
      --usage                给出简要的用法信息
  -V, --version              打印程序版本号

长选项的强制或可选参数对对应的短选项也是强制或可选的。

For bug reporting instructions, please see:
<https://bugs.launchpad.net/ubuntu/+source/glibc/+bugs>.

 

LDCONFIG(8)                                                   Linux Programmer's Manual                                                  LDCONFIG(8)

NAME
       ldconfig - configure dynamic linker run-time bindings

SYNOPSIS
       /sbin/ldconfig [ -nNvXV ] [ -f conf ] [ -C cache ] [ -r root ] directory ...
       /sbin/ldconfig -l [ -v ] library ...
       /sbin/ldconfig -p

DESCRIPTION
       ldconfig creates the necessary links and cache to the most recent shared libraries found in the directories 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 will attempt to deduce the type of ELF libs (i.e., libc5 or libc6/glibc) based on what C  libs,  if  any,  the  library  was  linked
       against.

       Some existing libs do not contain enough information to allow the deduction of their type.  Therefore, the /etc/ld.so.conf file format allows
       the specification of an expected type.  This is used only for those ELF libs which we can not work out.  The format is "dirname=TYPE",  where
       TYPE  can be libc4, libc5, or libc6.  (This syntax also works on the command line.)  Spaces are not allowed.  Also see the -p option.  ldcon‐
       fig should normally be run by the superuser as it may require write permission on some root owned directories and files.

OPTIONS
       -v     Verbose mode.  Print current version number, the name of each directory as it is scanned, and any links that are  created.   Overrides
              quiet mode.

       -n     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.

       -N     Don't rebuild the cache.  Unless -X is also specified, links are still updated.

       -X     Don't update links.  Unless -N is also specified, the cache is still rebuilt.

       -f conf
              Use conf instead of /etc/ld.so.conf.

       -C cache
              Use cache instead of /etc/ld.so.cache.

       -r root
              Change to and use root as the root directory.

       -l     Library mode.  Manually link individual libraries.  Intended for use by experts only.

       -p     Print the lists of directories and candidate libraries stored in the current cache.

 

发表评论

16 + 13 =

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据