📄 search-path.html
字号:
<html lang="en">
<head>
<title>The C Preprocessor</title>
<meta http-equiv="Content-Type" content="text/html">
<meta name="description" content="The C Preprocessor">
<meta name="generator" content="makeinfo 4.3">
<link href="http://www.gnu.org/software/texinfo/" rel="generator-home">
<!--
Copyright © 1987, 1989, 1991, 1992, 1993, 1994, 1995, 1996,
1997, 1998, 1999, 2000, 2001, 2002, 2003
Free Software Foundation, Inc.
<p>Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.1 or
any later version published by the Free Software Foundation. A copy of
the license is included in the
section entitled "GNU Free Documentation License".
<p>This manual contains no Invariant Sections. The Front-Cover Texts are
(a) (see below), and the Back-Cover Texts are (b) (see below).
<p>(a) The FSF's Front-Cover Text is:
<p>A GNU Manual
<p>(b) The FSF's Back-Cover Text is:
<p>You have freedom to copy and modify this GNU Manual, like GNU
software. Copies published by the Free Software Foundation raise
funds for GNU development.
-->
</head>
<body>
<div class="node">
<p>
Node:<a name="Search%20Path">Search Path</a>,
Next:<a rel="next" accesskey="n" href="Once-Only-Headers.html#Once-Only%20Headers">Once-Only Headers</a>,
Previous:<a rel="previous" accesskey="p" href="Include-Operation.html#Include%20Operation">Include Operation</a>,
Up:<a rel="up" accesskey="u" href="Header-Files.html#Header%20Files">Header Files</a>
<hr><br>
</div>
<h3 class="section">Search Path</h3>
<p>GCC looks in several different places for headers. On a normal Unix
system, if you do not instruct it otherwise, it will look for headers
requested with <code>#include <</code><var>file</var><code>></code> in:
<pre class="example"> /usr/local/include
/usr/lib/gcc-lib/<var>target</var>/<var>version</var>/include
/usr/<var>target</var>/include
/usr/include
</pre>
<p>For C++ programs, it will also look in <code>/usr/include/g++-v3</code>,
first. In the above, <var>target</var> is the canonical name of the system
GCC was configured to compile code for; often but not always the same as
the canonical name of the system it runs on. <var>version</var> is the
version of GCC in use.
<p>You can add to this list with the <code>-I</code><var>dir</var><code></code> command line
option. All the directories named by <code>-I</code> are searched, in
left-to-right order, <em>before</em> the default directories. The only
exception is when <code>dir</code> is already searched by default. In
this case, the option is ignored and the search order for system
directories remains unchanged.
<p>Duplicate directories are removed from the quote and bracket search
chains before the two chains are merged to make the final search chain.
Thus, it is possible for a directory to occur twice in the final search
chain if it was specified in both the quote and bracket chains.
<p>You can prevent GCC from searching any of the default directories with
the <code>-nostdinc</code> option. This is useful when you are compiling an
operating system kernel or some other program that does not use the
standard C library facilities, or the standard C library itself.
<code>-I</code> options are not ignored as described above when
<code>-nostdinc</code> is in effect.
<p>GCC looks for headers requested with <code>#include "</code><var>file</var><code>"</code>
first in the directory containing the current file, then in the same
places it would have looked for a header requested with angle brackets.
For example, if <code>/usr/include/sys/stat.h</code> contains
<code>#include "types.h"</code>, GCC looks for <code>types.h</code> first in
<code>/usr/include/sys</code>, then in its usual search path.
<p><code>#line</code> (see <a href="Line-Control.html#Line%20Control">Line Control</a>) does not change GCC's idea of the
directory containing the current file.
<p>You may put <code>-I-</code> at any point in your list of <code>-I</code> options.
This has two effects. First, directories appearing before the
<code>-I-</code> in the list are searched only for headers requested with
quote marks. Directories after <code>-I-</code> are searched for all
headers. Second, the directory containing the current file is not
searched for anything, unless it happens to be one of the directories
named by an <code>-I</code> switch.
<p><code>-I. -I-</code> is not the same as no <code>-I</code> options at all, and does
not cause the same behavior for <code><></code> includes that <code>""</code>
includes get with no special options. <code>-I.</code> searches the
compiler's current working directory for header files. That may or may
not be the same as the directory containing the current file.
<p>If you need to look for headers in a directory named <code>-</code>, write
<code>-I./-</code>.
<p>There are several more ways to adjust the header search path. They are
generally less useful. See <a href="Invocation.html#Invocation">Invocation</a>.
</body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -