LINUX-GCC compile-time header file and library file search path

Source: Internet
Author: User

First, the header file

GCC looks for the required header files at compile time:

* Search will start from -I

※ 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

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

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 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/lib can be executed by executing the results of the executable POS to find out which dynamic library, so that the 1th dynamic Library search order, and then delete the dynamic library, then execute the program POS, get the 2nd Dynamic Library search Path, Then we can delete the 2nd dynamic library which is searched, so the order of the Linux search dynamic Library will be obtained.
The output of the program pos execution and the corresponding relationship of the search to the dynamic library:

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.

LINUX-GCC compile-time header file and library file search path

Related Article

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.