⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 preprocessor-options.html

📁 gcc手册
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<html lang="en">

<head>

<title>Using the GNU Compiler Collection (GCC)</title>

<meta http-equiv="Content-Type" content="text/html">

<meta name="description" content="Using the GNU Compiler Collection (GCC)">

<meta name="generator" content="makeinfo 4.3">

<link href="http://www.gnu.org/software/texinfo/" rel="generator-home">

<!--

Copyright &copy; 1988, 1989, 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.2 or

any later version published by the Free Software Foundation; with the

Invariant Sections being "GNU General Public License" and "Funding

Free Software", the Front-Cover texts being (a) (see below), and with

the Back-Cover Texts being (b) (see below).  A copy of the license is

included in the section entitled "GNU Free Documentation License".



   <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="Preprocessor%20Options">Preprocessor Options</a>,

Next:<a rel="next" accesskey="n" href="Assembler-Options.html#Assembler%20Options">Assembler Options</a>,

Previous:<a rel="previous" accesskey="p" href="Optimize-Options.html#Optimize%20Options">Optimize Options</a>,

Up:<a rel="up" accesskey="u" href="Invoking-GCC.html#Invoking%20GCC">Invoking GCC</a>

<hr><br>

</div>



<h3 class="section">Options Controlling the Preprocessor</h3>



   <p>These options control the C preprocessor, which is run on each C source

file before actual compilation.



   <p>If you use the <code>-E</code> option, nothing is done except preprocessing. 

Some of these options make sense only together with <code>-E</code> because

they cause the preprocessor output to be unsuitable for actual

compilation.



   <p>You can use <code>-Wp,</code><var>option</var><code></code> to bypass the compiler driver

and pass <var>option</var> directly through to the preprocessor.  If

<var>option</var> contains commas, it is split into multiple options at the

commas.  However, many options are modified, translated or interpreted

by the compiler driver before being passed to the preprocessor, and

<code>-Wp</code> forcibly bypasses this phase.  The preprocessor's direct

interface is undocumented and subject to change, so whenever possible

you should avoid using <code>-Wp</code> and let the driver handle the

options instead.



     <dl>

<dt><code>-D </code><var>name</var><code></code>

     <dd>Predefine <var>name</var> as a macro, with definition <code>1</code>.



     <br><dt><code>-D </code><var>name</var><code>=</code><var>definition</var><code></code>

     <dd>Predefine <var>name</var> as a macro, with definition <var>definition</var>. 

There are no restrictions on the contents of <var>definition</var>, but if

you are invoking the preprocessor from a shell or shell-like program you

may need to use the shell's quoting syntax to protect characters such as

spaces that have a meaning in the shell syntax.



     <p>If you wish to define a function-like macro on the command line, write

its argument list with surrounding parentheses before the equals sign

(if any).  Parentheses are meaningful to most shells, so you will need

to quote the option.  With <code>sh</code> and <code>csh</code>,

<code>-D'</code><var>name</var><code>(</code><var>args<small class="dots">...</small></var><code>)=</code><var>definition</var><code>'</code> works.



     <p><code>-D</code> and <code>-U</code> options are processed in the order they

are given on the command line.  All <code>-imacros </code><var>file</var><code></code> and

<code>-include </code><var>file</var><code></code> options are processed after all

<code>-D</code> and <code>-U</code> options.



     <br><dt><code>-U </code><var>name</var><code></code>

     <dd>Cancel any previous definition of <var>name</var>, either built in or

provided with a <code>-D</code> option.



     <br><dt><code>-undef</code>

     <dd>Do not predefine any system-specific macros.  The common predefined

macros remain defined.



     <br><dt><code>-I </code><var>dir</var><code></code>

     <dd>Add the directory <var>dir</var> to the list of directories to be searched

for header files. 

Directories named by <code>-I</code> are searched before the standard

system include directories.  If the directory <var>dir</var> is a standard

system include directory, the option is ignored to ensure that the

default search order for system directories and the special treatment

of system headers are not defeated

.



     <br><dt><code>-o </code><var>file</var><code></code>

     <dd>Write output to <var>file</var>.  This is the same as specifying <var>file</var>

as the second non-option argument to <code>cpp</code>.  <code>gcc</code> has a

different interpretation of a second non-option argument, so you must

use <code>-o</code> to specify the output file.



     <br><dt><code>-Wall</code>

     <dd>Turns on all optional warnings which are desirable for normal code.  At

present this is <code>-Wcomment</code> and <code>-Wtrigraphs</code>.  Note that

many of the preprocessor's warnings are on by default and have no

options to control them.



     <br><dt><code>-Wcomment</code>

     <dd><dt><code>-Wcomments</code>

     <dd>Warn whenever a comment-start sequence <code>/*</code> appears in a <code>/*</code>

comment, or whenever a backslash-newline appears in a <code>//</code> comment. 

(Both forms have the same effect.)



     <br><dt><code>-Wtrigraphs</code>

     <dd>Warn if any trigraphs are encountered.  This option used to take effect

only if <code>-trigraphs</code> was also specified, but now works

independently.  Warnings are not given for trigraphs within comments, as

they do not affect the meaning of the program.



     <br><dt><code>-Wtraditional</code>

     <dd>Warn about certain constructs that behave differently in traditional and

ISO C.  Also warn about ISO C constructs that have no traditional C

equivalent, and problematic constructs which should be avoided.



     <br><dt><code>-Wimport</code>

     <dd>Warn the first time <code>#import</code> is used.



     <br><dt><code>-Wundef</code>

     <dd>Warn whenever an identifier which is not a macro is encountered in an

<code>#if</code> directive, outside of <code>defined</code>.  Such identifiers are

replaced with zero.



     <br><dt><code>-Wunused-macros</code>

     <dd>Warn about macros defined in the main file that are unused.  A macro

is <dfn>used</dfn> if it is expanded or tested for existence at least once. 

The preprocessor will also warn if the macro has not been used at the

time it is redefined or undefined.



     <p>Built-in macros, macros defined on the command line, and macros

defined in include files are not warned about.



     <p><strong>Note:</strong> If a macro is actually used, but only used in skipped

conditional blocks, then CPP will report it as unused.  To avoid the

warning in such a case, you might improve the scope of the macro's

definition by, for example, moving it into the first skipped block. 

Alternatively, you could provide a dummy use with something like:



     <pre class="smallexample">          #if defined the_macro_causing_the_warning

          #endif

          </pre>



     <br><dt><code>-Wendif-labels</code>

     <dd>Warn whenever an <code>#else</code> or an <code>#endif</code> are followed by text. 

This usually happens in code of the form



     <pre class="smallexample">          #if FOO

          ...

          #else FOO

          ...

          #endif FOO

          </pre>



     <p>The second and third <code>FOO</code> should be in comments, but often are not

in older programs.  This warning is on by default.



     <br><dt><code>-Werror</code>

     <dd>Make all warnings into hard errors.  Source code which triggers warnings

will be rejected.



     <br><dt><code>-Wsystem-headers</code>

     <dd>Issue warnings for code in system headers.  These are normally unhelpful

in finding bugs in your own code, therefore suppressed.  If you are

responsible for the system library, you may want to see them.



     <br><dt><code>-w</code>

     <dd>Suppress all warnings, including those which GNU CPP issues by default.



     <br><dt><code>-pedantic</code>

     <dd>Issue all the mandatory diagnostics listed in the C standard.  Some of

them are left out by default, since they trigger frequently on harmless

code.



     <br><dt><code>-pedantic-errors</code>

     <dd>Issue all the mandatory diagnostics, and make all mandatory diagnostics

into errors.  This includes mandatory diagnostics that GCC issues

without <code>-pedantic</code> but treats as warnings.



     <br><dt><code>-M</code>

     <dd>Instead of outputting the result of preprocessing, output a rule

suitable for <code>make</code> describing the dependencies of the main

source file.  The preprocessor outputs one <code>make</code> rule containing

the object file name for that source file, a colon, and the names of all

the included files, including those coming from <code>-include</code> or

<code>-imacros</code> command line options.



     <p>Unless specified explicitly (with <code>-MT</code> or <code>-MQ</code>), the

object file name consists of the basename of the source file with any

suffix replaced with object file suffix.  If there are many included

files then the rule is split into several lines using <code>\</code>-newline. 

The rule has no commands.



     <p>This option does not suppress the preprocessor's debug output, such as

<code>-dM</code>.  To avoid mixing such debug output with the dependency

rules you should explicitly specify the dependency output file with

<code>-MF</code>, or use an environment variable like

<code>DEPENDENCIES_OUTPUT</code> (see <a href="Environment-Variables.html#Environment%20Variables">Environment Variables</a>).  Debug output

will still be sent to the regular output stream as normal.



     <p>Passing <code>-M</code> to the driver implies <code>-E</code>, and suppresses

warnings with an implicit <code>-w</code>.



     <br><dt><code>-MM</code>

     <dd>Like <code>-M</code> but do not mention header files that are found in

system header directories, nor header files that are included,

directly or indirectly, from such a header.



     <p>This implies that the choice of angle brackets or double quotes in an

<code>#include</code> directive does not in itself determine whether that

header will appear in <code>-MM</code> dependency output.  This is a

slight change in semantics from GCC versions 3.0 and earlier.



     <br><dt><code>-MF </code><var>file</var><code></code>

     <dd><a name="-MF"></a>

When used with <code>-M</code> or <code>-MM</code>, specifies a

file to write the dependencies to.  If no <code>-MF</code> switch is given

the preprocessor sends the rules to the same place it would have sent

preprocessed output.



     <p>When used with the driver options <code>-MD</code> or <code>-MMD</code>,

<code>-MF</code> overrides the default dependency output file.



     <br><dt><code>-MG</code>

     <dd>In conjunction with an option such as <code>-M</code> requesting

dependency generation, <code>-MG</code> assumes missing header files are

generated files and adds them to the dependency list without raising

an error.  The dependency filename is taken directly from the

<code>#include</code> directive without prepending any path.  <code>-MG</code>

also suppresses preprocessed output, as a missing header file renders

this useless.



     <p>This feature is used in automatic updating of makefiles.



     <br><dt><code>-MP</code>

     <dd>This option instructs CPP to add a phony target for each dependency

other than the main file, causing each to depend on nothing.  These

dummy rules work around errors <code>make</code> gives if you remove header

files without updating the <code>Makefile</code> to match.



     <p>This is typical output:



     <pre class="example">          test.o: test.c test.h

          

          test.h:

          </pre>



     <br><dt><code>-MT </code><var>target</var><code></code>

     <dd>



     <p>Change the target of the rule emitted by dependency generation.  By

default CPP takes the name of the main input file, including any path,

deletes any file suffix such as <code>.c</code>, and appends the platform's

usual object suffix.  The result is the target.



     <p>An <code>-MT</code> option will set the target to be exactly the string you

specify.  If you want multiple targets, you can specify them as a single

argument to <code>-MT</code>, or use multiple <code>-MT</code> options.



     <p>For example, <code>-MT&nbsp;'$(objpfx)foo.o'</code> might give



     <pre class="example">          $(objpfx)foo.o: foo.c

          </pre>



     <br><dt><code>-MQ </code><var>target</var><code></code>

     <dd>



     <p>Same as <code>-MT</code>, but it quotes any characters which are special to

Make.  <code>-MQ&nbsp;'$(objpfx)foo.o'</code> gives



     <pre class="example">          $$(objpfx)foo.o: foo.c

          </pre>



     <p>The default target is automatically quoted, as if it were given with

<code>-MQ</code>.



     <br><dt><code>-MD</code>

     <dd><code>-MD</code> is equivalent to <code>-M -MF </code><var>file</var><code></code>, except that

<code>-E</code> is not implied.  The driver determines <var>file</var> based on

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -