Include header file, link database, System definition, total of the following sources specify GCC go there and find it.
Originally specified at compile time (in ~gcc/gcc/collect2.c:locatelib ()
Written in specs.
Later with-d-i-L specified
GCC environment variable settings (at compile time)
ld.so environment variable (this is run time)
I. Header documents
How does GCC find the required header files at compile time:
※ All header file searches will start with-I
※ then find GCC's environment variable 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 GCC is installed, then it is
/usr/include
Prefix/include
Prefix/xxx-xxx-xxx-gnulibc/include
Prefix/lib/gcc-lib/xxxx-xxx-xxx-gnulibc/2.8.1/include
Second, the library document
The options for function libraries such as cos () should be-LM
Compile the time:
※GCC will find L.
※ Find GCC's environment variable Library_path
※ Find the default directory/lib/usr/lib/usr/local/lib This is the original compile GCC written in the program
Third, the Run-time Dynamic Library search path (in the order of search)
1. 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).
2, through the environment variable ld_library_path specified dynamic library search path (when you specify multiple dynamic library search paths through this environment variable, the paths are separated by a colon ":")
3. Specify the dynamic library search path in the configuration file/etc/ld.so.conf
This is specified by the parameter "-wl,-rpath," of GCC. When multiple dynamic library search paths are specified, the paths are separated by a colon ":".
4, the default dynamic library search path/lib
5, the default dynamic library search path/usr/lib
Original address: http://blog.csdn.net/lily854212198/article/details/8060377