ldconfig configuration dynamic link path
ldconfig command
The purpose of the ldconfig commandMainly in the default search directory /lib
and the directory listed in the /usr/lib
dynamic library configuration file /etc/ld.so.conf
, search for a shareable dynamic link library (format such as lib*.so*), and then create a dynamic loader (ld.so) Required connection and cache files. The default cache file is /etc/ld.so.cache
, this file saves a sorted list of dynamic link library names. In order to make the dynamic link library shared by the system, you need to run the dynamic link library management command ldconfig, and this executable program is stored in the /sbin
directory.
ldconfig usually runs when the system starts, and when the user installs a new dynamic link library, you need to manually run this command.
The shared library mechanism under Linux uses a cache-like mechanism to store library information /etc/ld.so.cache
inside.
When the program is connected, first search it from this file, and then ld.so.conf
go to the path to find it in detail.
root cause
我们知道,内存的访问速度是硬盘的好几倍,所以,如果将常用的动态函数库加载到内存中(高速缓存,cache),当软件套件要采用动态函数库时,就不需要重新从硬盘里读出,这样就可以提高动态函数库的读取速度。这个时候需要ldconfig与 /etc/ld.so.conf的帮助
-
First, in the
/etc/ld.so.conf
write down of "I want to read the directory where the dynamic library cache" and pay attention, is a directory rather than a file. -
Using the
ldconfig
executable file the/etc/ld.so.conf
data read into the cache. -
While
/etc/ld.so.cache
recording the data file. -
In
/etc/ld.so.conf
following his party/usr/local/mysql/lib
, after savingldconfig
it, the new library can be found in the program is running. -
If you want to put lib outside of these two directories, but you don't want
/etc/ld.so.conf
to add things in it (or you don't have permission to add things). That's okay , that is, export a global variableLD_LIBRARY_PATH
, and then when you run the program, you will find the library in this directory. Generally speaking, this is only a temporary solution, used when there is no permission or temporary need. -
ldconfig
All of these things are related to running the program, not at all at compiling time. When compiling, you still -Lhave to add, don't get confused. -
In short, no matter what changes are made to the library, it is best to do
ldconfig
it, otherwise there will be some unexpected results. It won't take much time, but it will save a lot of things.
Points to note:
-
You don’t need to modify anything to add to
/lib
and/usr/lib
inside/etc/ld.so.conf
, but you need to adjust it after you are doneldconfig
, otherwise the library will not be found. -
When you want to add something other than the above two directories, you must modify
/etc/ld.so.conf
it and then call itldconfig
, otherwise you won’t find it.
As shown in the figure:
Which is stored dynamic link library path, remember that if you add a ldconfig
bit
Through the LD_LIBRARY_PATH environment variable
By setting LD_LIBRARY_PATH
environment variables, you can also configure the path of the dynamic link library