Search Path for header files and library files during Linux-GCC Compilation

Source: Internet
Author: User

I. header files
 
Find the required header file during GCC Compilation:
 
※The search starts with-I.
 
※Find the GCC environment variable c_include_path, cplus_include_path, objc_include_path.
 
※Find the specified directory.
/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 installing GCC, it is
/Usr/include

Prefix/include
Prefix/xxx-gnulibc/include
Prefix/lib/GCC-lib/XXXX-xxx-gnulibc/2.8.1/include
 
Ii. library files

During Compilation:
※Gcc will go to-l
※Find the GCC environment variable LIBRARY_PATH.
 
※Find the default directory/lib:/usr/local/lib: which was written in the original compile GCC.ProgramInternal

Iii. Search Path of dynamic library during runtime

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 this environment variable, the paths are separated by colons)
3. Compile the targetCode Specifies the dynamic library search path of the Program (you can also specify the dynamic library search path of the program when compiling the target code.
This is specified through the GCC parameter "-wl,-rpath. When multiple dynamic library search paths are specified, the paths are separated by colons (:).
4. The default dynamic library search path/lib/usr/lib can be used to find the dynamic library to be searched by executing the executable file POS, in this way, you can obtain the search sequence of 1st dynamic databases, delete the dynamic library, execute the POs program, obtain the search paths of 2nd dynamic databases, and then delete 2nd searched dynamic libraries, in this way, the sequence of Linux dynamic database search is obtained.
The output result of the program POS execution corresponds to the searched dynamic library:

Specifies the path of the dynamic library corresponding to the dynamic library used for the POs output result.
. // The dynamic library search path specified when libpos. So is used to compile the target code
/Root/test/ENV/lib/libpos. So the dynamic library search path specified by the Environment Variable LD_LIBRARY_PATH
/Root/test/CONF/lib/libpos. So configuration file/etc/lD. So. conf
/Lib/libpos. So default dynamic library search path/lib
/Usr/lib/libpos. So default dynamic library search path/usr/lib

The search path sequence of a dynamic library is as follows:

1. The dynamic library search path specified when the target code is compiled;
2. The dynamic library search path specified by the Environment Variable LD_LIBRARY_PATH;
3. The dynamic library search path specified in the configuration file/etc/lD. So. conf;
4. The default dynamic library search path is/lib/usr/lib.

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.