1 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
---|
2 | <html>
|
---|
3 | <!-- Copyright (C) 2022 Richard Stallman and Free Software Foundation, Inc.
|
---|
4 |
|
---|
5 | (The work of Trevis Rothwell and Nelson Beebe has been assigned or
|
---|
6 | licensed to the FSF.)
|
---|
7 |
|
---|
8 | Permission is granted to copy, distribute and/or modify this document
|
---|
9 | under the terms of the GNU Free Documentation License, Version 1.3 or
|
---|
10 | any later version published by the Free Software Foundation; with the
|
---|
11 | Invariant Sections being "GNU General Public License," with the
|
---|
12 | Front-Cover Texts being "A GNU Manual," and with the Back-Cover
|
---|
13 | Texts as in (a) below. A copy of the license is included in the
|
---|
14 | section entitled "GNU Free Documentation License."
|
---|
15 |
|
---|
16 | (a) The FSF's Back-Cover Text is: "You have the freedom to copy and
|
---|
17 | modify this GNU manual. Buying copies from the FSF supports it in
|
---|
18 | developing GNU and promoting software freedom." -->
|
---|
19 | <!-- Created by GNU Texinfo 6.7, http://www.gnu.org/software/texinfo/ -->
|
---|
20 | <head>
|
---|
21 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
---|
22 | <title>Search Path (GNU C Language Manual)</title>
|
---|
23 |
|
---|
24 | <meta name="description" content="Search Path (GNU C Language Manual)">
|
---|
25 | <meta name="keywords" content="Search Path (GNU C Language Manual)">
|
---|
26 | <meta name="resource-type" content="document">
|
---|
27 | <meta name="distribution" content="global">
|
---|
28 | <meta name="Generator" content="makeinfo">
|
---|
29 | <link href="index.html" rel="start" title="Top">
|
---|
30 | <link href="Symbol-Index.html" rel="index" title="Symbol Index">
|
---|
31 | <link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
|
---|
32 | <link href="Header-Files.html" rel="up" title="Header Files">
|
---|
33 | <link href="Once_002dOnly-Headers.html" rel="next" title="Once-Only Headers">
|
---|
34 | <link href="include-Operation.html" rel="prev" title="include Operation">
|
---|
35 | <style type="text/css">
|
---|
36 | <!--
|
---|
37 | a.summary-letter {text-decoration: none}
|
---|
38 | blockquote.indentedblock {margin-right: 0em}
|
---|
39 | div.display {margin-left: 3.2em}
|
---|
40 | div.example {margin-left: 3.2em}
|
---|
41 | div.lisp {margin-left: 3.2em}
|
---|
42 | kbd {font-style: oblique}
|
---|
43 | pre.display {font-family: inherit}
|
---|
44 | pre.format {font-family: inherit}
|
---|
45 | pre.menu-comment {font-family: serif}
|
---|
46 | pre.menu-preformatted {font-family: serif}
|
---|
47 | span.nolinebreak {white-space: nowrap}
|
---|
48 | span.roman {font-family: initial; font-weight: normal}
|
---|
49 | span.sansserif {font-family: sans-serif; font-weight: normal}
|
---|
50 | ul.no-bullet {list-style: none}
|
---|
51 | -->
|
---|
52 | </style>
|
---|
53 |
|
---|
54 |
|
---|
55 | </head>
|
---|
56 |
|
---|
57 | <body lang="en">
|
---|
58 | <span id="Search-Path"></span><div class="header">
|
---|
59 | <p>
|
---|
60 | Next: <a href="Once_002dOnly-Headers.html" accesskey="n" rel="next">Once-Only Headers</a>, Previous: <a href="include-Operation.html" accesskey="p" rel="prev">include Operation</a>, Up: <a href="Header-Files.html" accesskey="u" rel="up">Header Files</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Symbol-Index.html" title="Index" rel="index">Index</a>]</p>
|
---|
61 | </div>
|
---|
62 | <hr>
|
---|
63 | <span id="Search-Path-1"></span><h4 class="subsection">26.4.3 Search Path</h4>
|
---|
64 |
|
---|
65 | <p>GCC looks in several different places for header files to be included.
|
---|
66 | On the GNU system, and Unix systems, the default directories for
|
---|
67 | system header files are:
|
---|
68 | </p>
|
---|
69 | <div class="example">
|
---|
70 | <pre class="example"><var>libdir</var>/gcc/<var>target</var>/<var>version</var>/include
|
---|
71 | /usr/local/include
|
---|
72 | <var>libdir</var>/gcc/<var>target</var>/<var>version</var>/include-fixed
|
---|
73 | <var>libdir</var>/<var>target</var>/include
|
---|
74 | /usr/include/<var>target</var>
|
---|
75 | /usr/include
|
---|
76 | </pre></div>
|
---|
77 |
|
---|
78 | <p>The list may be different in some operating systems. Other
|
---|
79 | directories are added for C++.
|
---|
80 | </p>
|
---|
81 | <p>In the above, <var>target</var> is the canonical name of the system GCC was
|
---|
82 | configured to compile code for; often but not always the same as the
|
---|
83 | canonical name of the system it runs on. <var>version</var> is the version
|
---|
84 | of GCC in use.
|
---|
85 | </p>
|
---|
86 | <p>You can add to this list with the <samp>-I<var>dir</var></samp> command-line
|
---|
87 | option. All the directories named by <samp>-I</samp> are searched, in
|
---|
88 | left-to-right order, <em>before</em> the default directories. The only
|
---|
89 | exception is when <samp>dir</samp> is already searched by default. In
|
---|
90 | this case, the option is ignored and the search order for system
|
---|
91 | directories remains unchanged.
|
---|
92 | </p>
|
---|
93 | <p>Duplicate directories are removed from the quote and bracket search
|
---|
94 | chains before the two chains are merged to make the final search chain.
|
---|
95 | Thus, it is possible for a directory to occur twice in the final search
|
---|
96 | chain if it was specified in both the quote and bracket chains.
|
---|
97 | </p>
|
---|
98 | <p>You can prevent GCC from searching any of the default directories with
|
---|
99 | the <samp>-nostdinc</samp> option. This is useful when you are compiling an
|
---|
100 | operating system kernel or some other program that does not use the
|
---|
101 | standard C library facilities, or the standard C library itself.
|
---|
102 | <samp>-I</samp> options are not ignored as described above when
|
---|
103 | <samp>-nostdinc</samp> is in effect.
|
---|
104 | </p>
|
---|
105 | <p>GCC looks for headers requested with <code>#include "<var>file</var>"<!-- /@w --></code>
|
---|
106 | first in the directory containing the current file, then in the
|
---|
107 | <em>quote directories</em> specified by <samp>-iquote</samp> options, then in
|
---|
108 | the same places it looks for a system header. For example, if
|
---|
109 | <samp>/usr/include/sys/stat.h</samp> contains <code>#include "types.h"<!-- /@w --></code>,
|
---|
110 | GCC looks for <samp>types.h</samp> first in <samp>/usr/include/sys</samp>, then in
|
---|
111 | the quote directories and then in its usual search path.
|
---|
112 | </p>
|
---|
113 | <p><code>#line</code> (see <a href="Line-Control.html">Line Control</a>) does not change GCC’s idea of the
|
---|
114 | directory containing the current file.
|
---|
115 | </p>
|
---|
116 | <span id="index-quote-directories"></span>
|
---|
117 | <p>The <samp>-I-</samp> is an old-fashioned, deprecated way to specify the
|
---|
118 | quote directories. To look for headers in a directory named <samp>-</samp>,
|
---|
119 | specify <samp>-I./-</samp>. There are several more ways to adjust the
|
---|
120 | header search path. See <a href="https://gcc.gnu.org/onlinedocs/gcc/invocation.html#invocation">Invoking GCC</a> in <cite>Using the GNU Compiler Collection</cite>.
|
---|
121 | </p>
|
---|
122 | <hr>
|
---|
123 | <div class="header">
|
---|
124 | <p>
|
---|
125 | Next: <a href="Once_002dOnly-Headers.html" accesskey="n" rel="next">Once-Only Headers</a>, Previous: <a href="include-Operation.html" accesskey="p" rel="prev">include Operation</a>, Up: <a href="Header-Files.html" accesskey="u" rel="up">Header Files</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Symbol-Index.html" title="Index" rel="index">Index</a>]</p>
|
---|
126 | </div>
|
---|
127 |
|
---|
128 |
|
---|
129 |
|
---|
130 | </body>
|
---|
131 | </html>
|
---|