Difference between LIBRARY_PATH and LD_LIBRARY_PATH environment variables

LIBRARY_PATH and LD_LIBRARY_PATH are two environment variables under Linux. The meanings and functions of the two are as follows:

The LIBRARY_PATH environment variable is used to specify the path for finding shared libraries when searching for dynamic link libraries during program compilation . For example, specifying gcc compilation needs to use The directory of the dynamic link library.

The LD_LIBRARY_PATH environment variable is used to specify paths other than the system default path when searching for dynamic link libraries during program loading and running . Note that the path specified in LD_LIBRARY_PATH will be searched before the system default path.

Difference and use:
When developing, set LIBRARY_PATH so that gcc can find the dynamic link libraries needed for compilation.
When publishing, set LD_LIBRARY_PATH so that when the program loads and runs, it can automatically find the required dynamic link library.

The linker options in GCC are -rpath and -rpath-link. After reading man ld, this is roughly what it means:


GCC link options -L, -rpath-link and -rpath -L: When "linking", go to The searched directory, that is, all the libraries in the -lFOO option, will be searched from the directory specified by -L first, and then the default place.
-rpath_link (or -rpath-link): This is also used for "linking". For example, if you specify that you need FOO.so, but FOO.so itself needs BAR.so, which you did not specify, Instead, FOO.so refers to it. At this time, it will be searched from the path given by -rpath-link first.
-rpath: The directory to look for when "running". When running, to find the .so file, it will find it from the place specified in this option. For cross-compiling, it only works with the --sysroot option.


That is, the path specified by -rpath will be recorded in the generated executable program for runtime.
-rpath-link is only used when linking.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327058488&siteId=291194637