Describes the environment variables that GCC uses during the compile phase and during the program run phase.
Environment variables used in GCC compilation
The variable used by GCC when compiling.
C_include_path
GCC compile-time lookup header file directory list. Like what:
echo $C _include_path# outputs##/usr/include:/usr/local/include
Cplus_include_path
Similar to C_include_path, suitable for g++.
Library_path
GCC and g++ Find a directory listing of library files at the link stage of the compilation, such as:
echo $LIBRARY _path# outputs##/usr/lib:/usr/lib64:/usr/local/lib:/usr/local/lib64
Environment variables to be used when the program is run
Variables to be used during the run of the program.
Ld_library_path
A directory listing of dynamic link libraries (. So files) is found when the program runs. Like what:
echo $LD _library_path# outputs##/usr/lib:/usr/lib64:/usr/local/lib:/usr/local/lib64
Ld_preload
The LD_PRELOAD
dynamic- man ld.so
link libraries defined in the (Reference Ld_preload section) are loaded before other dynamic-link libraries, thus overwriting the same-name symbols (function variables, etc.) defined in other link libraries, and the complete example can refer to Test-ld-preload. It is important to note that when you overwrite a function in C function library in C + +, you should use extern "C"
block name mangling.
suld_preload=/usr/lib/libtsocks.so apt-get Update
Note that ld_preload cannot be used in the sudo command. 1
Debian dynamic link Library search path
On Debian systems, if modifying ld_library_path is not used, you can modify the/etc/ld.so.conf or/etc/ld.so.conf.d/*.conf, add the library directory as a row to the Conf file above, Then run the ldconfig command.
Vi/etc/ld.so.conf.d/my.confldconfig
or customize a library directory's configuration file (for example, my.conf), and then load the profile with Ldconfig-f/path/to/my.conf.
VI ~/project/test/ld_lib.confldconfig-f ~/project/test/ld_lib.conf
Examples of ld_lib.conf.
/usr/local/lib/path/to/your/shared/lib/directory
Ld.so the order in which to find library files
Ld.so is used to find and load a dynamic link library file (*.so), as detailed in the man ld.so.
Ld.so loads the shared libraries needed by a program, prepares the program to run, and then runs it. Unless explicitly specified via the-static option to LD dur? ing compilation, all Linux programs is incomplete and require further linking at run time.
The necessary GKFX libraries needed by the program is searched for in the following order O Using the Environment V Ariable Ld_library_path (Ld_aout_library_path for a.out programs). Except If the executable is a setuid/setgid binary, in which case it's ignored. O from the cache file/etc/ld.so. Cache which contains a compiled list of candidate libraries previously found in the Augmented library path. o in the default Path/lib, and Then/usr/lib.
For /etc/ld.so.conf.d/
conf files in, the alphabetical order is loaded sequentially. Suppose you need to /usr/local/lib
overwrite the system's library file with the library file in the directory, and you can put /usr/local/lib
the included configuration file in the top row.
$ ls-1/etc/ld.so.conf.d00_libc.confx86_64-linux-gnu.confzz_i386-biarch-compat.conf$ Cat 00_libc.conf/usr/local/ Lib
Reading materials
- Environment variables from "a Introduction to GCC"
- The difference between Library_path and LD_LIBRARY_PATH environment variables
- Linux:set OR Change the Library Path
- Ld.so (8)
GCC-related environment variables