First, the header file GCC looks for the required header files at compile time: * Search will start with-I (gcc parameter, specify header file search location)
※ Then find the environment variable of GCC C_include_path,cplus_include_path,objc_include_path ※ Find the default catalogue again/usr/include
/usr/local/include/usr/lib/gcc-lib/i386-linux/2.95.2/include/usr/lib/gcc-lib/i386-linux/2.95.2/. /.. /.. /.. /include/g++-3/usr/lib/gcc-lib/i386-linux/2.95.2/. /.. /.. /.. /i386-linux/include But if there is a given prefix when the GCC is installed, then it is/usr/include
Prefix/includePrefix/xxx-xxx-xxx-gnulibc/includePrefix/lib/gcc-lib/xxxx-xxx-xxx-gnulibc/2.8.1/include Second, the library fileCompile the time:※GCC will find-L.※ Re-search for GCC environment variable Library_path ※ Find the default directory/lib:/usr/lib:/usr/local/lib: This is the original compile GCC when written in the program
Third, run-time dynamic Library search Path
1. Specify the dynamic library search path in the configuration file/etc/ld.so.conf
2. Specify the dynamic library search path through the environment variable Ld_library_path (when multiple dynamic library search paths are specified through the environment variable, the paths are separated by a colon ":") 3. Specify the dynamic library search path for the program when compiling the target code (you can also specify the program's dynamic Library search path when compiling the target code). This is specified through the GCC parameter "-wl,-rpath,". When you specify multiple dynamic library search paths, the paths are separated by a colon ":"4, the default dynamic library search path/lib/usr/libyou can find out which dynamic library to search for by executing the results from the executable pos, get the 1th Dynamic Library search order, and then delete the dynamic library. then execute the program POS, get the 2nd Dynamic Library search path, and then delete the 2nd search dynamic Library, In this way, you will get the sequencing of the Linux search dynamic library. The corresponding relationship between the output of the program POS execution and the search dynamic library is shown in table 1 Dynamic library Search path specified by the dynamic library corresponding to the program POS output results././libpos.so The Dynamic library search path specified when compiling the target code /root/test/env/lib/root/test/env/lib/libpos.so environment variable ld_library_path the specified dynamic library search path /root/test/conf/lib/root/test/conf/lib/libpos.so The dynamic Library search path specified in configuration file/etc/ld.so.conf /lib/lib/libpos.so The default dynamic library search path/lib /usr/lib/usr/lib/libpos.so The default dynamic library search path/usr/lib The order of search path search for dynamic libraries is: 1. The dynamic library search path specified when compiling the target code;2. Environment variable LD_LIBRARY_PATH the specified dynamic library search path;
3. The dynamic library search path specified in the configuration file/etc/ld.so.conf;
4. The default dynamic library search path/lib/usr/lib.
The shared library mechanism under Linux uses a caching-like mechanism to store the library information in/etc/ld.so.cache.
When the program is connected, look it up from inside the file, and then go to the ld.so.conf path to find it in detail.
That's why you modified ld.so.conf to run Ldconfig again.
Add a little, ldconfig in/sbin.
Ldconfig a few points to note
1. To/lib and/usr/lib inside add things, is not modified/etc/ld.so.conf, but after the end to adjust ldconfig, otherwise the library will not find
2. If you want to add things to the above two directories, be sure to modify the/etc/ld.so.conf, and then call Ldconfig, otherwise you will not find
For example, install a MySQL to/usr/local/mysql,mysql there are a lot of libraries under the/usr/local/mysql/lib, then you need to add/usr/local/on the top of/etc/ld.so.conf Mysql/lib, must be the first line, and to be assigned to the library file directory, but not its parent directory, after saving Ldconfig, the new library can be found when the program is running. The shared library paths under this directory can be saved directly through Ldconfig/usr/local/mysql/lib to Ld.so.cache, when they are not written to the ld.so.conf file.
3. If you want to put Lib outside of these two directories, but do not want to add things in the/etc/ld.so.conf (or do not have permission to add things). That can also be, export a global variable ld_library_path, and then run the program will go to this directory to find the LIBRARY. In general, this is a temporary solution that is used when there is no authority or temporary need.
4. These things that ldconfig do are related to running the program, and have nothing to do with the compile time. Compile the time or the addition-l will have to add, do not confuse.
5. In short, it is no matter what you do about the library changes, it is best to ldconfig a bit, otherwise there will be some unexpected results. It won't take much time, but it will save a lot of things.
Ldconfig usually runs at system startup, and when a user installs a new dynamic-link library, they need to run the command manually.
The ldconfig command line usage is as follows:
ldconfig [-v|--verbose] [-n] [-n] [-X] [-F CONF] [-C CACHE] [-R ROOT] [-l] [-p|--print-cache]
[-C FORMAT] [--format=format] [-v] [-?| --help|--usage] path ...
ldconfig The options available are described below:
(1)-V or--verbose: With this option, Ldconfig displays the directory being scanned and the dynamic link library that was searched, and the name of the connection it created.
(2)-N: With this option, Ldconfig scans only the directories specified by the command line, does not scan the default directory (/lib,/usr/lib), and does not scan directories listed in the configuration file/etc/ld.so.conf.
(3)-N: This option indicates that Ldconfig does not rebuild the cache file (/etc/ld.so.cache). If the-X option is not used, the connection to the file is updated Ldconfig as usual.
(4)-x: This option indicates that Ldconfig does not update the file's connection. If the-n option is not used, the cache file is updated normally.
(5)-F CONF: This option specifies that the configuration file for the dynamic link library is CONF and the system defaults to/etc/ld.so.conf.
(6)-C cache: This option specifies that the generated cache file is cached, and the default is/etc/ld.so.cache, which holds a list of ordered shareable dynamic link libraries.
(7)-R root: This option changes the root of the application to be root (called the chroot function). When this option is selected, the system default configuration file/etc/ld.so.conf, which corresponds to root/etc/ld.so.conf. As with-R /usr/zzz, when you open the profile/etc/ld.so.conf, the/usr/zzz/etc/ld.so.conf file is actually opened. With this option, you can greatly increase the flexibility of dynamic link library Management .
(8)-L: Typically, Ldconfig will automatically establish a connection to a dynamic-link library when it searches for a dynamic-link library. When this option is selected, the expert mode is entered, and the connection needs to be set manually. The general user does not use this item.
(9)-P or--print-cache: This option instructs Ldconfig to print out the names of all shared libraries that are saved by the current cache file.
(+)-C format or--format=format: This option specifies the format in which the cache file is used, in total three types: LD (old format), new (newer format), and Compat (the default format).
(one)-V: This option prints out the version information for Ldconfig and then exits.
(12)-or--help or--usage: These three options have the same effect, which is to let Ldconfig print out its Help information and then exit.
The shared library mechanism under Linux uses a caching-like mechanism to store the library information in/etc/ld.so.cache.
when the program is connected, look it up from inside the file, and then go to the ld.so.conf path to find it in detail.
That's why you modified ld.so.conf to run Ldconfig again .
3. Path issues for dynamic libraries
There are three ways to successfully find a dynamic library in order to execute the program:
(1) Copy the library to the/usr/lib and/lib directories. Then run Ldconfig
(2) Add the path of the library to the LD_LIBRARY_PATH environment variable. For example, dynamic library libhello.so in the/home/ting/lib directory, in bash, for example, use the command:
$export ld_library_path= $LD _library_path:/home/ting/lib
(3) Modify the/etc/ld.so.conf file, add the path where the library is located to the end of the file, and perform a ldconfig refresh. In this way, all library files in the joined directory are visible,
Note: The file can be found at link time (usually through the-l library file directory), does not mean that the run is also able to find the file, only through the above three ways to ensure that the runtime to find the dynamic library. (Static library does not exist this problem because the static library in LD, the contents of the file has been copied to the target file, in the run is no longer to find)transferred from: http://blog.csdn.net/rlj021/archive/2008/12/16/3530939.aspx
27>>GCC compile-time header file and library file search path