"Linux Notes" Ldconfig, LDD

Source: Internet
Author: User

First, Ldconfig

Ldconfig is a dynamic link Library Management command that runs the management command--ldconfig of the dynamic link library in order for the dynamic link library to be shared with the system. The purpose of the Ldconfig command is to search for a shareable dynamic-link library (in the form of a previous introduction, lib*.so*), mainly in the default search directory (/lib and/usr/lib) and in the directory listed in the dynamic library configuration file/etc/ld.so.conf. In order to create the connection and cache files required by the dynamic loader (ld.so), the cache file defaults to/etc/ld.so.cache, which holds the list of dynamically linked library names that have been sorted.

The shared library mechanism under Linux uses a cache-like mechanism to store library information in/etc/ Ld.so.cache inside, the program connects the time first from the file inside to find, and then to ld.so.conf in the path inside to find out, this is why modified ld.so.conf to re-run ldconfig the reason.

Ldconfig a few points to note:

1) to/lib and/usr/lib inside add things, is not modified/etc/ld.so.conf, but after the end to adjust ldconfig, otherwise the library will not find;

2) Want to add things to the above two directories, be sure to modify the/etc/ld.so.conf, and then call Ldconfig, otherwise you will not find. For example, install a MySQL to/usr/local/mysql,mysql there are a lot of libraries under the/usr/local/mysql/lib, then you need to add a line under/etc/ld.so.conf/usr/local/ Mysql/lib, save after Ldconfig, the new library can be found in the program run;

3) If you want to put Lib outside of these two directories, but do not want to add things in the/etc/ld.so.conf (or do not have permission to add things). That can also be, export a global variable ld_library_path, and then run the program will go to this directory to find the LIBRARY. In general, this is a temporary solution that is used when there is no authority or temporary need;

4) All these things that ldconfig do are related to running the program, and they have nothing to do with the compile time. Compile time or the addition of-l will have to add, do not confuse;

5) In short, is no matter what to do about the changes in the library, it is best to ldconfig a bit, otherwise there will be some unexpected results. It won't take much time, but it will save a lot of things.

The Ldconfig command line usage is as follows:

Ldconfig [-v|--verbose] [-n] [-n] [-X] [-F CONF] [-C CACHE] [-R ROOT] [-l] [-p|--print-cache]

[-C FORMAT] [--format=format] [-V] [-?| --help|--usage] path ...

Ldconfig the options available are described below:

1)-V or--verbose: With this option, Ldconfig will display the directory being scanned and the dynamic link library that was searched, as well as the name of the connection it created;

2)-N: With this option, Ldconfig only scans the directory specified by the command line, does not scan the default directory (/lib,/usr/lib), and does not scan directories listed in the configuration file/etc/ld.so.conf;

3)-N: This option indicates that Ldconfig does not rebuild the cache file (/etc/ld.so.cache), and if the-X option is not used, ldconfig updates the connection to the file as usual;

4)-X: This option indicates that Ldconfig does not update the file connection, and if the-n option is not used, the cache file is updated normally;

5)-F CONF: This option specifies that the configuration file for the dynamic link library is CONF and the system defaults to/etc/ld.so.conf;

6)-C cache: This option specifies that the generated cache file is cached, and the default is/etc/ld.so.cache, which holds the list of well-ordered shareable dynamic-link libraries;

7)-R root: This option changes the root directory of the application to be root (which is implemented by calling the Chroot function), and when selected, the default configuration file/etc/ld.so.conf the system, which corresponds to root/etc/ld.so.conf. When using-r/usr/zzz, when opening the configuration file/etc/ld.so.conf, the actual open is/usr/zzz/etc/ld.so.conf file, with this option, can greatly increase the flexibility of dynamic link library management;

8)-L: Normally, Ldconfig will automatically establish the connection of dynamic link library when searching dynamic link library, select this item, will enter expert mode, need to set up the connection manually, the general user does not use this item;

9)-P or--print-cache: This option instructs Ldconfig to print out the names of all shared libraries saved by the current cache file;

)-C format or--format=format: This option specifies the format used for the cache file, in total three types: LD (old format), new (newer format) and COMPAT (compatible format, this is the default format);

One)-V: This option prints out the version information of the ldconfig and then exits;

12)-? or--help or--usage: These three options work the same, letting Ldconfig print out their help information and then exit.

Second, LDD

Function: Used to view the shared libraries required for a program to run, often to resolve problems that the program cannot run because of a missing library file.

LDD command principle

1, first LDD is not an executable program, but just a shell script;

2, LDD can display the dependency of the executable module, the principle is by setting a series of environment variables, such as: Ld_trace_loaded_objects, Ld_warn, Ld_bind_now, Ld_library_version, LD _verbose and so on. When the LD_TRACE_LOADED_OBJECTS environment variable is not empty, any executable program will display only the module's dependency while it is running, and the program does not actually execute. You can test it at the shell terminal:
(1) Export Ld_trace_loaded_objects=1

(2) Execute any program, such as LS, to see the results of the program running

3. LDd shows how the dependency of the executable module works, and its essence is realized by ld-linux.so (the loader of the Elf Dynamic Library). We know that the Ld-linux.so module works before the executable module and gets control, so when those environment variables are set, ld-linux.so chooses the dependency that shows the executable module.

4, can actually directly execute ld-linux.so module, such as:/lib/ld-linux.so.2--list program (this is equivalent to LDD program).

"Linux Notes" Ldconfig, LDD

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.