The path of the default search header file and library file for Linux under GCC

Source: Internet
Author: User

First, the header file
How GCC looks for the required header files at compile time:
※ The search for header file will start with-I
※ then find the environment variables of GCCC_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
Library file But if there is a given prefix when the 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 file
The options for the Cos () function library are more-LM
Compile 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 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," as shown in Example 3. 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
You 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
Combined with the above results, the order of search path search for dynamic library is as follows:
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;
5. The default dynamic library search path/usr/lib.

The path of the default search header file and library file for Linux under GCC

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.