ldconfig configuration dynamic link path

ldconfig configuration dynamic link path

Extension link

ldconfig command

The purpose of the ldconfig commandMainly in the default search directory /liband the directory listed in the /usr/libdynamic 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 /sbindirectory.

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.cacheinside.
When the program is connected, first search it from this file, and then ld.so.confgo to the path to find it in detail.

root cause

我们知道,内存的访问速度是硬盘的好几倍,所以,如果将常用的动态函数库加载到内存中(高速缓存,cache),当软件套件要采用动态函数库时,就不需要重新从硬盘里读出,这样就可以提高动态函数库的读取速度。这个时候需要ldconfig与 /etc/ld.so.conf的帮助
  • First, in the /etc/ld.so.confwrite 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 ldconfigexecutable file the /etc/ld.so.confdata read into the cache.

  • While /etc/ld.so.cacherecording the data file.

  • In /etc/ld.so.conffollowing his party /usr/local/mysql/lib, after saving ldconfigit, 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.confto add things in it (or you don't have permission to add things). That's okay , that is, export a global variable LD_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.

  • ldconfigAll 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 ldconfigit, 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 /liband /usr/libinside /etc/ld.so.conf, but you need to adjust it after you are done ldconfig, 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.confit and then call it ldconfig, otherwise you won’t find it.

As shown in the figure:

Which is stored dynamic link library path, remember that if you add a ldconfigbit

Through the LD_LIBRARY_PATH environment variable

By setting LD_LIBRARY_PATHenvironment variables, you can also configure the path of the dynamic link library

Guess you like

Origin blog.csdn.net/ahelloyou/article/details/115176113