Current location - Health Preservation Learning Network - Healthy weight loss - View the commands that linux currently loads library files.
View the commands that linux currently loads library files.
Ldd< executable file name >; See which system dynamic link libraries are linked to executable files.

Nm < executable file name >; See what symbols are in the executable file.

Strip & lt executable file name >; Removing the symbol table can simplify the executable file.

If we want to extract some text information from an executable program, we can also use the strings command.

String < executable file name >;

Dynamic shared libraries on Linux operating system can be roughly divided into three categories:

1, operating system level * * * shared library and basic system tool library.

For example, libc.so, libz.so, libpthread.so, etc., these system libraries will be placed in the /lib and /usr/lib directories. If it is a 64-bit operating system, there will also be /lib64 and /usr /lib64 directories. If the operating system has a graphical interface, there will be a /usr/X 1 1R6/lib directory, and if it is a 64-bit operating system, there will be a /usr/x 1r6/lib64 directory. There may also be other system library directories for specific Linux versions.

The integrity and correct version of these system library files ensure the normal operation of various programs on Linux.

2, application-level system * * * enjoy the library.

Libraries that are not included in the operating system but may be used by many applications are usually placed in the /usr/local/lib and /usr/local/lib64 directories. Many self-compiled and installed programs will automatically add /usr/local /lib to the -L parameter of gcc at compile time, and will automatically go to /usr/local/lib to find the * * * library at run time.

The above two kinds of dynamic * * * libraries will be found automatically by the application, and you don't need to set up or worry about them. Why is this? Because by default, these directories are added to the search path of the dynamic linker. The search path of Linux system * * * library is defined in the configuration file /etc/ld.so.conf, and the content format of this file is roughly as follows:

/usr/X 1 1R6/lib64

/usr/X 1 1R6/lib

/usr/local/lib

/lib64

/library

/usr/lib64

/usr/lib

/usr/local/lib64

/usr/local/ImageMagick/lib

Assuming that the ImageMagick graphic library compiled and installed by ourselves is in the /usr/local/ImageMagick directory, and we hope that other applications can use the dynamic * * * library of ImageMagick, then we only need to add the /usr/local/ImageMagick/lib directory to the /etc/ld.so.conf file, and then execute the: ldconfig command.

Ldcofig will search all the above directories and create a cache file /etc/ld.so.cache for the * * * enjoyment library. To confirm that ldconfig has searched ImageMagick's library, we can use the strings command introduced above to extract text information from ld.so.cache for inspection:

strings/etc/LD . so . cache | grep ImageMagick

The output result is:

/usr/local/ImageMagick/lib/libwand . so . 10

/usr/local/ImageMagick/lib/libwand . so

/usr/local/ImageMagick/lib/libmagick . so . 10

/usr/local/ImageMagick/lib/libmagick . so

/usr/local/ImageMagick/lib/libmagick++ . so . 10

/usr/local/ImageMagick/lib/libmagick++。 therefore

It worked!

3. A dynamic * * * library dedicated to applications

There are many * * * shared libraries that are only used by specific applications, so there is no need to join the system library path to avoid version conflict between * * * shared libraries of applications. Therefore, Linux can also temporarily specify the * * * shared library search path of the application by setting the environment variable LD_LIBRARY_PATH. Just like the example we cited above, we can preset LD_LIBRARY_PATH in the startup script of the application, and specify the additional * * * shared library search path of the application, so that the application can find it.