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

📄 precompiled-headers.html

📁 自己收集的linux入门到学懂高级编程书集 包括linux程序设计第三版
💻 HTML
字号:
<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.6"><!--Copyright &copy; 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,1999, 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.   <p>Permission is granted to copy, distribute and/or modify this documentunder the terms of the GNU Free Documentation License, Version 1.2 orany later version published by the Free Software Foundation; with theInvariant Sections being "GNU General Public License" and "FundingFree Software", the Front-Cover texts being (a) (see below), and withthe Back-Cover Texts being (b) (see below).  A copy of the license isincluded 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.--><meta http-equiv="Content-Style-Type" content="text/css"><style type="text/css"><!--  pre.display { font-family:inherit }  pre.format  { font-family:inherit }  pre.smalldisplay { font-family:inherit; font-size:smaller }  pre.smallformat  { font-family:inherit; font-size:smaller }  pre.smallexample { font-size:smaller }  pre.smalllisp    { font-size:smaller }--></style></head><body><div class="node"><p>Node:&nbsp;<a name="Precompiled%20Headers">Precompiled Headers</a>,Next:&nbsp;<a rel="next" accesskey="n" href="Running-Protoize.html#Running%20Protoize">Running Protoize</a>,Previous:&nbsp;<a rel="previous" accesskey="p" href="Environment-Variables.html#Environment%20Variables">Environment Variables</a>,Up:&nbsp;<a rel="up" accesskey="u" href="Invoking-GCC.html#Invoking%20GCC">Invoking GCC</a><hr><br></div><h3 class="section">Using Precompiled Headers</h3><p>Often large projects have many header files that are included in everysource file.  The time the compiler takes to process these header filesover and over again can account for nearly all of the time required tobuild the project.  To make builds faster, GCC allows users to`precompile' a header file; then, if builds can use the precompiledheader file they will be much faster.   <p><strong>Caution:</strong> There are a few known situations where GCC willcrash when trying to use a precompiled header.  If you have troublewith a precompiled header, you should remove the precompiled headerand compile without it.  In addition, please use GCC's on-linedefect-tracking system to report any problems you encounter withprecompiled headers.  See <a href="Bugs.html#Bugs">Bugs</a>.   <p>To create a precompiled header file, simply compile it as you would anyother file, if necessary using the <code>-x</code> option to make the drivertreat it as a C or C++ header file.  You will probably want to use atool like <code>make</code> to keep the precompiled header up-to-date whenthe headers it contains change.   <p>A precompiled header file will be searched for when <code>#include</code> isseen in the compilation.  As it searches for the included file(see <a href="../cpp/Search-Path.html#Search%20Path">Search Path</a>) thecompiler looks for a precompiled header in each directory just before itlooks for the include file in that directory.  The name searched for isthe name specified in the <code>#include</code> with <code>.gch</code> appended.  Ifthe precompiled header file can't be used, it is ignored.   <p>For instance, if you have <code>#include "all.h"</code>, and you have<code>all.h.gch</code> in the same directory as <code>all.h</code>, then theprecompiled header file will be used if possible, and the originalheader will be used otherwise.   <p>Alternatively, you might decide to put the precompiled header file in adirectory and use <code>-I</code> to ensure that directory is searchedbefore (or instead of) the directory containing the original header. Then, if you want to check that the precompiled header file is alwaysused, you can put a file of the same name as the original header in thisdirectory containing an <code>#error</code> command.   <p>This also works with <code>-include</code>.  So yet another way to useprecompiled headers, good for projects not designed with precompiledheader files in mind, is to simply take most of the header files used bya project, include them from another header file, precompile that headerfile, and <code>-include</code> the precompiled header.  If the header fileshave guards against multiple inclusion, they will be skipped becausethey've already been included (in the precompiled header).   <p>If you need to precompile the same header file for differentlanguages, targets, or compiler options, you can instead make a<em>directory</em> named like <code>all.h.gch</code>, and put each precompiledheader in the directory, perhaps using <code>-o</code>.  It doesn't matterwhat you call the files in the directory, every precompiled header inthe directory will be considered.  The first precompiled headerencountered in the directory that is valid for this compilation willbe used; they're searched in no particular order.   <p>There are many other possibilities, limited only by your imagination,good sense, and the constraints of your build system.   <p>A precompiled header file can be used only when these conditions apply:     <ul><li>Only one precompiled header can be used in a particular compilation.     <li>A precompiled header can't be used once the first C token is seen.  Youcan have preprocessor directives before a precompiled header; you caneven include a precompiled header from inside another header, so long asthere are no C tokens before the <code>#include</code>.     <li>The precompiled header file must be produced for the same language asthe current compilation.  You can't use a C precompiled header for a C++compilation.     <li>The precompiled header file must be produced by the same compilerversion and configuration as the current compilation is using. The easiest way to guarantee this is to use the same compiler binaryfor creating and using precompiled headers.     <li>Any macros defined before the precompiled header is included musteither be defined in the same way as when the precompiled header wasgenerated, or must not affect the precompiled header, which usuallymeans that the they don't appear in the precompiled header at all.     <p>The <code>-D</code> option is one way to define a macro before aprecompiled header is included; using a <code>#define</code> can also do it. There are also some options that define macros implicitly, like<code>-O</code> and <code>-Wdeprecated</code>; the same rule applies to macrosdefined this way.     </p><li>If debugging information is output when using the precompiledheader, using <code>-g</code> or similar, the same kind of debugging informationmust have been output when building the precompiled header.  However,a precompiled header built using <code>-g</code> can be used in a compilationwhen no debugging information is being output.     <li>The same <code>-m</code> options must generally be used when buildingand using the precompiled header.  See <a href="Submodel-Options.html#Submodel%20Options">Submodel Options</a>,for any cases where this rule is relaxed.     <li>Each of the following options must be the same when building and usingthe precompiled header:     <pre class="smallexample">          -fexceptions -funit-at-a-time          </pre>     <li>Some other command-line options starting with <code>-f</code>,<code>-p</code>, or <code>-O</code> must be defined in the same way as whenthe precompiled header was generated.  At present, it's not clearwhich options are safe to change and which are not; the safest choiceis to use exactly the same options when generating and using theprecompiled header.  The following are known to be safe:     <pre class="smallexample">          -pedantic-errors          </pre>   </ul>   <p>For all of these except the last, the compiler will automaticallyignore the precompiled header if the conditions aren't met.  If youfind an option combination that doesn't work and doesn't cause theprecompiled header to be ignored, please consider filing a bug report,see <a href="Bugs.html#Bugs">Bugs</a>.   </body></html>

⌨️ 快捷键说明

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