Linux dynamic link library management, linux Dynamic Link Library

Source: Internet
Author: User

Linux dynamic link library management, linux Dynamic Link Library


1. ldd command

Ldd view program dependent Libraries
Ldd: used to view the shared libraries required for running a program. It is often used to solve some problems that the program cannot run due to a lack of library files.
Example: view the library on which the test program runs:

/Opt/app/todeav1/test $ ldd test
Libstdc ++. so.6 =>/usr/lib64/libstdc ++. so.6 (0x00000039a7e00000)
Libm. so.6 =>/lib64/libm. so.6 (0x0000003996400000)
Libgcc_s.so.1 =>/lib64/libgcc_s.so.1 (0x00000039a5600000)
Libc. so.6 =>/lib64/libc. so.6 (0x0000003995800000)
/Lib64/ld-linux-x86-64.so.2 (0x0000003995400000)

• Column 1: database required by the program
• Column 2: database provided by the system corresponding to the library required by the program
• Column 3: Start address of Library Loading

Through the above information, we can get the following information:
1. By comparing the first and second columns, we can analyze whether the libraries required by the program match the ones actually provided by the system.
2. By observing the third column, we can know the starting position of the symbols in the current library in the address space of the corresponding process.

If a dependent database cannot be found, you can use this command to quickly locate the problem;

Principle: ldd is not an executable program, but a shell script; ldd shows the dependency of the executable module working principle, the essence is through the ld-linux.so (elf dynamic library loader). The ld-linux.so module works prior to the executable module program and gets control, so when those environment variables above are set, the ld-linux.so selects the dependency that shows the executable module.

Ii. ldconfig command

Ldconfig is a dynamic link library management command to share the dynamic link library with the system.

Main uses of ldconfig:

Search for/lilb and/usr/lib by default, and the library files under the directories listed in the configuration file/etc/ld. so. conf.

Search for a shared dynamic link library. The format of the library file is lib ***. so. ** to create a dynamic loader (ld. so) the required connection and cache file.

The default cache file is/etc/ld. so. cache. This file stores the list of Dynamic Linked Library names sorted.

Ldconfig is usually run when the system starts. When you install a new dynamic link library, you need to manually run this command.

Ldconfig command parameters:

1.-v or -- verbose: When this option is used, ldconfig displays the directory being scanned, The searched dynamic link library, and the name of the connection it created.

2.-n: When this option is used, ldconfig only scans the directory specified by the command line and does not scan the default directory (/lib,/usr/lib ), nor scan the configuration file/etc/ld. so. conf directory.

3.-N: This option indicates that ldconfig does not recreate the cache file (/etc/ld. so. cache). If the-X option is not used, ldconfig updates the file connection as usual.

4.-X: This option indicates that ldconfig does not update the file connection. If the-N option is not used, the cached file will be updated normally.

5.-f CONF: This option specifies that the configuration file of the dynamic link library is CONF, and the default value is/etc/ld. so. conf.

6.-c cache: This option specifies that the generated CACHE file is CACHE. The default value is/etc/ld. so. cache. This file stores the list of dynamically linked libraries that can be shared in the sorted order.

7.-r ROOT: This option changes the ROOT directory of the application to ROOT (implemented by calling the chroot function ). when this option is selected, the system default configuration file/etc/ld. so. conf, which corresponds to ROOT/etc/ld. so. conf. for example, when-r/usr/zzz is used, open the configuration file/etc/ld. so. in conf,/usr/zzz/etc/ld is actually enabled. so. conf file. this option can greatly increase the flexibility of dynamic link library management.

8.-l: Generally, ldconfig automatically establishes a connection to the dynamic link library when searching for a dynamic link library. when this option is selected, the expert mode is enabled. You need to manually set the connection. this option is not required for general users.

9.-p or -- print-cache: This option indicates that ldconfig prints the names of all the shared libraries saved in the current cache file.

10.-c FORMAT or -- format = FORMAT: This option is used to specify the FORMAT used by the cache file. There are three types: ld (old format), new (new FORMAT) and compat (compatible format, which is the default format ).

11.-V: This option prints the version information of ldconfig and then exits.

12.-Or -- help or -- usage: the three options share the same role. ldconfig prints the help information and exits.

Ldconfig:

1. add something to/lib and/usr/lib without modifying/etc/ld. so. conf file, but after adding it, you need to call ldconfig. Otherwise, the added library will not be found.

2. If the added library is not in/lib and/usr/lib, you must modify/etc/ld. so. conf file, append the path of the library to the file, and then call the ldconfig command again. For example, when installing MySQL, the library file/usr/local/mysql/lib needs to be appended to the/etc/ld. so. conf file. The command is as follows:

# Echo "/usr/local/mysql/lib">/etc/ld. so. conf

# Ldconfig-v | grep mysql

3. LD_LIBRARY_PATH

If the added library is not in/lib or/usr/lib, but has no permission to operate it. To write the/etc/ld. so. conf file, you need to write a global variable LD_LIBRARY_PATH to the export.



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.