linux dynamic link library search method; search dynamic link library location; difference between LIBRARY_PATH and LD_LIBRARY_PATH; difference between LD_LIBRARY_PATH and LD_RUN_PATH;

When configuring the previous project today, I found that some dynamic link libraries have changed. I want to see which dynamic link libraries are currently being used by the application, and I further checked some information;

The following records the process of linux dynamic link library search method and dynamic link library location configuration:

The difference between LIBRARY_PATH and LD_LIBRARY_PATH: ( reference link )

LIBRARY_PATH is used by gcc before compilation to search directories containing static and shared libraries that need to be linked to your program.

LD_LIBRARY_PATH is used by your program to search directories containing shared libraries after it has been successfully compiled and linked.

As pointed below, your libraries can be static or shared. If it is static then the code is copied over into your program and you don't need to search for the library after your program is compiled and linked. If your library is shared then it needs to be dynamically linked to your program and that's when LD_LIBRARY_PATH comes into play. 

The difference between LD_LIBRARY_PATH and LD_RUN_PATH: ( reference link )

LD_RUN_PATH is used for the link time resolution of libraries whilst LD_LIBRARY_PATH is used for run time resolution of libraries. LD_RUN_PATH Specifies the directories that are to be searched for libraries at both link and run time.

LD_LIBRARY_PATH indicates to the dynamic loader to search the colon delimited paths for libraries required to execute the binary.  LD_RUN_PATH is used by the linker to specify where to look for libraries only at run time.  This differs ever so slightly from LD_LIBRARY_PATH in that this set of paths are not searched during link time.

Dynamic link library search path configuration:

1. It can be configured using environment variables such as LD_LIBRARY_PATH above  ;

2. You can use the /etc/ld.so.conf global configuration file to configure the search path when the dynamic link library is running; then use the ldconfig command to load /etc/ld.so.conf into ld.so.cache (Requires root privileges);

3. Then use: ldconfig -p | grep "your lib" to find the location of the required dynamic link library;

4. For existing programs, you can use ldd "your bin" to directly view the link library required by the current program;

Keep updated, please indicate the source for reprinting; For more content, please follow cnblogs.com/xuyaowen;

/etc/ld.so.conf.d/x86_64-linux-gnu.conf, multi-architecture support configuration, take x86_64 as an example:

# Multiarch support
/usr/local/lib/x86_64-linux-gnu
/lib/x86_64-linux-gnu
/usr/lib/x86_64-linux-gnu

Keep updating;

Guess you like

Origin blog.csdn.net/qq_45533841/article/details/112211840