Search Path for header files and library files in linux

Source: Internet
Author: User
Linux header file and library file search path-Linux general technology-Linux programming and kernel information. The following is a detailed description. Include header file, link database, system definition, there are a total of the following sources designated gcc to find.
The ~ Gcc/collect2.c: locatelib ()
Written in specs
Later, it was specified with-D-I-L.
Gcc environment variable setting (during compilation)
Environment Variable of ld. so (this is run time)
1. header file
How to find the required header file during gcc Compilation:
※Therefore, the header file search starts from-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

2. library files
-Lm is required for the options of cos () and other function libraries.
During Compilation:
※Gcc will go to-L
※Find the gcc environment variable LIBRARY_PATH.
※Find the internal directory/lib/usr/local/lib, which was written in the program at the time of compile gcc.
3. Search Path of dynamic library during runtime
Method 1: Specify the dynamic library search path in the configuration file/etc/ld. so. conf.
Method 2: Use the environment variable LD_LIBRARY_PATH to specify the dynamic library search path (when multiple dynamic library search paths are specified through the environment variable, use the colon ":" to separate the paths)
Method 3: Specify the dynamic library search path of the program when compiling the target code. 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," (as shown in Example 3 ). When multiple dynamic library search paths are specified, the paths are separated by colons)
4. Default dynamic library search path/lib
5. Default dynamic library search path/usr/lib
You can find the dynamic library you have searched for by executing the executable file pos and obtain the search sequence of the 1st dynamic databases. Then, you can delete the dynamic library,
Then execute the pos program to obtain 2nd dynamic library search paths, and then delete 2nd searched dynamic libraries,
In this way, the sequence of Linux dynamic database search is obtained.
The correspondence between output results of program pos execution and the searched dynamic library is shown in table 1.
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
Based on the above results, we can see that the search path sequence of the dynamic library is:
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. Default dynamic library search path/lib;
5. The default dynamic library search path is/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.