ldconfig is usually run when the system starts. When the user installs a new dynamic link library, this command needs to be run manually.
grammar
ldconfig [-v|--verbose] [-n] [-N] [-X] [-f CONF] [-C CACHE] [-r ROOT] [-l] [-p|--print-cache] [-c FORMAT] [--format=FORMAT] [-V] [-?|--<span class="wp_keywordlink">help</span>|--usage] path...
Options
-v或--verbose:用此选项时,ldconfig将显示正在扫描的目录及搜索到的动态链接库,还有它所创建的连接的名字。
-n:用此选项时,ldconfig仅扫描命令行指定的目录,不扫描默认目录(/lib、/usr/lib),也不扫描配置文件/etc/ld.so.conf所列的目录。
-N:此选项指示ldconfig不重建缓存文件(/etc/ld.so.cache),若未用-X选项,ldconfig照常更新文件的连接。
-X:此选项指示ldconfig不更新文件的连接,若未用-N选项,则缓存文件正常更新。
-f CONF:此选项指定动态链接库的配置文件为CONF,系统默认为/etc/ld.so.conf。
-C CACHE:此选项指定生成的缓存文件为CACHE,系统默认的是/etc/ld.so.cache,此文件存放已排好序的可共享的动态链接库的列表。
-r ROOT:此选项改变应用程序的根目录为ROOT(是调用chroot函数实现的)。选择此项时,系统默认的配置文件/etc/ld.so.conf,实际对应的为ROOT/etc/ld.so.conf。如用-r /usr/zzz时,打开配置文件/etc/ld.so.conf时,实际打开的是/usr/zzz/etc/ld.so.conf文件。用此选项,可以大大增加动态链接库管理的灵活性。
-l:通常情况下,ldconfig搜索动态链接库时将自动建立动态链接库的连接,选择此项时,将进入专家模式,需要手工设置连接,一般用户不用此项。
-p或--print-cache:此选项指示ldconfig打印出当前缓存文件所保存的所有共享库的名字。
-c FORMAT 或 --format=FORMAT:此选项用于指定缓存文件所使用的格式,共有三种:old(老格式),new(新格式)和compat(兼容格式,此为默认格式)。
-V:此选项打印出ldconfig的版本信息,而后退出。
-? 或 --help 或 --usage:这三个选项作用相同,都是让ldconfig打印出其帮助信息,而后退出。
A few things to note about ldconfig:
- There is no need to modify /etc/ld.so.conf when adding things to /lib and /usr/lib, but you need to adjust ldconfig after finishing, otherwise the library will not be found.
- When you want to add something to the above two directories, you must modify /etc/ld.so.conf and then call ldconfig, otherwise it will not be found.
- For example, if you install a mysql to /usr/local/mysql, mysql has a lot of libraries under /usr/local/mysql/lib, then you need to add a line /usr under /etc/ld.so.conf /local/mysql/lib, save it and run ldconfig so that the new library can be found when the program is running.
- If you want to put lib outside these two directories, but you don’t want to add things to /etc/ld.so.conf (or you don’t have permission to add things). That's okay, just export a global variable LD_LIBRARY_PATH, and then when you run the program, it will go to this directory to find the library. Generally speaking, this is only a temporary solution, used when there is no permission or temporary need.
- These things ldconfig does are related to the running time of the program and have nothing to do with the compilation time. You still need to add -L when compiling, don't get confused.
- In short, no matter what changes are made to the library, it is best to ldconfig, otherwise some unexpected results will occur. It won't take much time, but it will save a lot of trouble.
- Furthermore, the file header such as libdb-4.3.so will contain information related to the library name (that is, it contains "libdb-4.3.so", which can be viewed with the strings command), so just modify the file name to impersonate someone. Already recognized libraries (such as libdb-4.8.so) will not work. For this purpose, you can directly modify the configuration information in the Makefile of the compiled library and specify a special library name.
The above is the detailed content of Detailed explanation of command-ldconfig. For more information, please follow other related articles on the PHP Chinese website!