Search Path of the include file in GCC

Source: Internet
Author: User

This is not a complex question, but many answers on the Internet are not comprehensive; I have found a comprehensive one (tested ):

Reference http://blog.csdn.net/fjb2080/archive/2010/01/23/5247494.aspx

# There are two types of include:

# Include <syshead. h>
# Include "userhead. H"
The header file contains the system header file. The header file contains your own header file in double quotation marks.

The following are some rules for using # include:

1) if you use the <> included header file, the path after the-I option is first searched (that is, the-I option during GCC compilation), followed by the standard system header file path.

2) the header file contained with "" will first search for the current working directory, and then the search path is the same as the path searched by the header file contained in "<>.

3) in Unix systems, the standard header file path is:

/Usr/local/include
/Usr/lib/GCC-lib/target/version/include
/Usr/target/include
/Usr/include
4) there are generally two independent header file search path chains. One is the path indicated by-I, the other is the system header file path and the Directory operated after-prefix,-withprefix, and-idirafter.

5) If GCC compiles a C ++ Program, The Preprocessor will first search for the/usr/include/g ++ V3 directory before searching the directory mentioned above, v3 is the c ++ version in your GCC.

6) run the "add path name" command in the header file, for example, # include <sys/time. h>. The time. h file will be searched for in the SYS directory of the system directory.

7) a slash is generally used as the directory delimiter, and some systems even use different characters as the delimiter (for example, a backslash ).

8) # The file name included after include is the file name, such as ABC * D. h. This file must have ABC * D. h. This file is not abckkkd. h. These files * cannot be interpreted as any 

   It is a real character.

9) you can use a specified name as the header file after the # include command, for example:

# Define bogheader "bog_3.h"
# Include bogheader
10) after the # include command, except the header file and comments contained, nothing else can be included.

11) # The line command cannot change the current working directory.

12) the-I-option can change the directory specified by-I.

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.