/etc/ld.so.conf and/etc/ld.so.cache–linux Dynamic shared libraries

Source: Internet
Author: User
Tags imagemagick

Executable program can not find the dynamic shared library to link, this is Linux above compile and run the program is very easy to encounter problems, next we want to explore how to set up the program to find dynamic shared library behavior.
The dynamic shared libraries above the Linux operating system are broadly divided into three categories:
1. Operating system-level shared libraries and underlying system Tools library
For example, libc.so, libz.so, libpthread.so, and so on, these system libraries will be placed under the/lib and/usr/lib directories, if it is a 64-bit operating system, it will also
There are/lib64 and/usr/lib64 directories. If the operating system has a graphical interface, there will also be a/usr/x11r6/lib directory, if it is a 64-bit operating system, but also
There is a/usr/x11r6/lib64 directory. There may also be other specific Linux versions of the system library directory.
The complete and correct version of these system library files ensures that the various programs on Linux are functioning properly.
2, application-level system sharing Library
Not the operating system comes with, but libraries that may be shared by many applications are typically placed under both/usr/local/lib and/usr/local/lib64 directories. A lot
The program you compile and install will automatically add/usr/local/lib to GCC's-l parameter at compile time, while running it automatically to/usr/local/lib under the
Find a shared library.
With these two types of dynamic shared libraries, applications will automatically find them and don't need your extra setup and worry. What is this for? Because these directories are added by default
into the search path of the dynamic Link program. The Linux system shared library search path is defined in the/etc/ld.so.conf configuration file. The content format of this file
Roughly as follows:
1./usr/x11r6/lib64
2./usr/x11r6/lib
3./usr/local/lib
4./lib64
5./lib
6./usr/lib64
7./usr/lib
8./usr/local/lib64
9./usr/local/imagemagick/lib
Let's say we compiled our own installed ImageMagick graphics library under the/usr/local/imagemagick directory and want other applications to be able to use ImageMagick's
Dynamic Shared library, then we just need to add the/usr/local/imagemagick/lib directory into the/etc/ld.so.conf file, and then execute: Ldconfig command.
Ldcofig will search all of the above directories and create a cache file/etc/ld.so.cache for the shared library. In order to confirm that ldconfig has searched the ImageMagick library, I
We can use the strings command described above to extract text messages from the Ld.so.cache to check:
1. Strings/etc/ld.so.cache | grep ImageMagick
The output is:
1./usr/local/imagemagick/lib/libwand.so.10
2./usr/local/imagemagick/lib/libwand.so
3./usr/local/imagemagick/lib/libmagick.so.10
4./usr/local/imagemagick/lib/libmagick.so
5./usr/local/imagemagick/lib/libmagick++.so.10
6./usr/local/imagemagick/lib/libmagick++.so
It's done!
3. Application-Exclusive dynamic shared library
There are many shared libraries that are only used by specific applications, so it is not necessary to join the system library path to avoid version conflicts between the shared libraries of the application. So Linux Also
You can temporarily specify the application's shared library search path by setting the environment variable Ld_library_path, as in the example above, we can apply
The program's startup script is pre-set Ld_library_path, specifying the shared library search path attached to the application, allowing the application to find it.


/etc/ld.so.conf and/etc/ld.so.cache–linux Dynamic shared libraries

Related Article

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.