1. Loading path
- Default library loading path, such as: /lib and /usr/lib
- ldconfig specifies the loading path: specify the dynamic library search path in the configuration file /etc/ld.so.conf
- Compile specified loading path: specify the dynamic library search path of the program when compiling the target code, through the gcc parameter "-Wl,-rpath,"
- Environment variable specifies the loading path: specify the dynamic library search path through the environment variable LD_LIBRARY_PATH
2. Loading order
Loading search priority of dynamic library, from high to low:
- Compile the specified loading path
- The environment variable specifies the load path (LD_LIBRARY_PATH)
- ldconfig specifies the loading path
- Default library load path
illustrate:
"/usr/local/lib" and "/usr/local/lib/x86_64-linux-gnu, /lib/x86_64-linux-gnu and /usr/lib/x86_64-linux-gnu are all ldconfig specified loading paths , the locations are in /etc/ld.so.conf.d/libc.conf and /etc/ld.so.conf.d/x86_64-linux-gnu.conf respectively.
Look at the content of the /etc/ld.so.conf file: include /etc/ld.so.conf.d/*.conf, so it is actually each configuration file in the /etc/ld.so.conf.d directory, My environment is as follows:
libc.conf
libnginx.conf
x86_64-linux-gnu.conf
According to the above environment, the more detailed library path priority is:
- Compile the specified loading path
- The environment variable specifies the load path (LD_LIBRARY_PATH)
- ldconfig specifies the loading path: /usr/local/lib
- ldconfig specifies the loading path: the content of libnginx.conf
- ldconfig specifies the loading path: /usr/local/lib/x86_64-linux-gnu, /lib/x86_64-linux-gnu and /usr/lib/x86_64-linux-gnu
- Default library loading paths: /lib and /usr/lib