Invoking-GCC.html 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <html>
  3. <!-- Copyright (C) 1988-2017 Free Software Foundation, Inc.
  4. Permission is granted to copy, distribute and/or modify this document
  5. under the terms of the GNU Free Documentation License, Version 1.3 or
  6. any later version published by the Free Software Foundation; with the
  7. Invariant Sections being "Funding Free Software", the Front-Cover
  8. Texts being (a) (see below), and with the Back-Cover Texts being (b)
  9. (see below). A copy of the license is included in the section entitled
  10. "GNU Free Documentation License".
  11. (a) The FSF's Front-Cover Text is:
  12. A GNU Manual
  13. (b) The FSF's Back-Cover Text is:
  14. You have freedom to copy and modify this GNU Manual, like GNU
  15. software. Copies published by the Free Software Foundation raise
  16. funds for GNU development. -->
  17. <!-- Created by GNU Texinfo 5.2, http://www.gnu.org/software/texinfo/ -->
  18. <head>
  19. <title>Using the GNU Compiler Collection (GCC): Invoking GCC</title>
  20. <meta name="description" content="Using the GNU Compiler Collection (GCC): Invoking GCC">
  21. <meta name="keywords" content="Using the GNU Compiler Collection (GCC): Invoking GCC">
  22. <meta name="resource-type" content="document">
  23. <meta name="distribution" content="global">
  24. <meta name="Generator" content="makeinfo">
  25. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  26. <link href="index.html#Top" rel="start" title="Top">
  27. <link href="Option-Index.html#Option-Index" rel="index" title="Option Index">
  28. <link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
  29. <link href="index.html#Top" rel="up" title="Top">
  30. <link href="Option-Summary.html#Option-Summary" rel="next" title="Option Summary">
  31. <link href="Standards.html#Standards" rel="prev" title="Standards">
  32. <style type="text/css">
  33. <!--
  34. a.summary-letter {text-decoration: none}
  35. blockquote.smallquotation {font-size: smaller}
  36. div.display {margin-left: 3.2em}
  37. div.example {margin-left: 3.2em}
  38. div.indentedblock {margin-left: 3.2em}
  39. div.lisp {margin-left: 3.2em}
  40. div.smalldisplay {margin-left: 3.2em}
  41. div.smallexample {margin-left: 3.2em}
  42. div.smallindentedblock {margin-left: 3.2em; font-size: smaller}
  43. div.smalllisp {margin-left: 3.2em}
  44. kbd {font-style:oblique}
  45. pre.display {font-family: inherit}
  46. pre.format {font-family: inherit}
  47. pre.menu-comment {font-family: serif}
  48. pre.menu-preformatted {font-family: serif}
  49. pre.smalldisplay {font-family: inherit; font-size: smaller}
  50. pre.smallexample {font-size: smaller}
  51. pre.smallformat {font-family: inherit; font-size: smaller}
  52. pre.smalllisp {font-size: smaller}
  53. span.nocodebreak {white-space:nowrap}
  54. span.nolinebreak {white-space:nowrap}
  55. span.roman {font-family:serif; font-weight:normal}
  56. span.sansserif {font-family:sans-serif; font-weight:normal}
  57. ul.no-bullet {list-style: none}
  58. -->
  59. </style>
  60. </head>
  61. <body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
  62. <a name="Invoking-GCC"></a>
  63. <div class="header">
  64. <p>
  65. Next: <a href="C-Implementation.html#C-Implementation" accesskey="n" rel="next">C Implementation</a>, Previous: <a href="Standards.html#Standards" accesskey="p" rel="prev">Standards</a>, Up: <a href="index.html#Top" accesskey="u" rel="up">Top</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Option-Index.html#Option-Index" title="Index" rel="index">Index</a>]</p>
  66. </div>
  67. <hr>
  68. <a name="GCC-Command-Options"></a>
  69. <h2 class="chapter">3 GCC Command Options</h2>
  70. <a name="index-GCC-command-options"></a>
  71. <a name="index-command-options"></a>
  72. <a name="index-options_002c-GCC-command"></a>
  73. <p>When you invoke GCC, it normally does preprocessing, compilation,
  74. assembly and linking. The &ldquo;overall options&rdquo; allow you to stop this
  75. process at an intermediate stage. For example, the <samp>-c</samp> option
  76. says not to run the linker. Then the output consists of object files
  77. output by the assembler.
  78. See <a href="Overall-Options.html#Overall-Options">Options Controlling the Kind of Output</a>.
  79. </p>
  80. <p>Other options are passed on to one or more stages of processing. Some options
  81. control the preprocessor and others the compiler itself. Yet other
  82. options control the assembler and linker; most of these are not
  83. documented here, since you rarely need to use any of them.
  84. </p>
  85. <a name="index-C-compilation-options"></a>
  86. <p>Most of the command-line options that you can use with GCC are useful
  87. for C programs; when an option is only useful with another language
  88. (usually C++), the explanation says so explicitly. If the description
  89. for a particular option does not mention a source language, you can use
  90. that option with all supported languages.
  91. </p>
  92. <a name="index-cross-compiling"></a>
  93. <a name="index-specifying-machine-version"></a>
  94. <a name="index-specifying-compiler-version-and-target-machine"></a>
  95. <a name="index-compiler-version_002c-specifying"></a>
  96. <a name="index-target-machine_002c-specifying"></a>
  97. <p>The usual way to run GCC is to run the executable called <code>gcc</code>, or
  98. <code><var>machine</var>-gcc</code> when cross-compiling, or
  99. <code><var>machine</var>-gcc-<var>version</var></code> to run a specific version of GCC.
  100. When you compile C++ programs, you should invoke GCC as <code>g++</code>
  101. instead. See <a href="Invoking-G_002b_002b.html#Invoking-G_002b_002b">Compiling C++ Programs</a>,
  102. for information about the differences in behavior between <code>gcc</code>
  103. and <code>g++</code> when compiling C++ programs.
  104. </p>
  105. <a name="index-grouping-options"></a>
  106. <a name="index-options_002c-grouping"></a>
  107. <p>The <code>gcc</code> program accepts options and file names as operands. Many
  108. options have multi-letter names; therefore multiple single-letter options
  109. may <em>not</em> be grouped: <samp>-dv</samp> is very different from &lsquo;<samp><span class="nolinebreak">-d</span>&nbsp;<span class="nolinebreak">-v</span></samp>&rsquo;<!-- /@w -->.
  110. </p>
  111. <a name="index-order-of-options"></a>
  112. <a name="index-options_002c-order"></a>
  113. <p>You can mix options and other arguments. For the most part, the order
  114. you use doesn&rsquo;t matter. Order does matter when you use several
  115. options of the same kind; for example, if you specify <samp>-L</samp> more
  116. than once, the directories are searched in the order specified. Also,
  117. the placement of the <samp>-l</samp> option is significant.
  118. </p>
  119. <p>Many options have long names starting with &lsquo;<samp>-f</samp>&rsquo; or with
  120. &lsquo;<samp>-W</samp>&rsquo;&mdash;for example,
  121. <samp>-fmove-loop-invariants</samp>, <samp>-Wformat</samp> and so on. Most of
  122. these have both positive and negative forms; the negative form of
  123. <samp>-ffoo</samp> is <samp>-fno-foo</samp>. This manual documents
  124. only one of these two forms, whichever one is not the default.
  125. </p>
  126. <p>See <a href="Option-Index.html#Option-Index">Option Index</a>, for an index to GCC&rsquo;s options.
  127. </p>
  128. <table class="menu" border="0" cellspacing="0">
  129. <tr><td align="left" valign="top">&bull; <a href="Option-Summary.html#Option-Summary" accesskey="1">Option Summary</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">Brief list of all options, without explanations.
  130. </td></tr>
  131. <tr><td align="left" valign="top">&bull; <a href="Overall-Options.html#Overall-Options" accesskey="2">Overall Options</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">Controlling the kind of output:
  132. an executable, object files, assembler files,
  133. or preprocessed source.
  134. </td></tr>
  135. <tr><td align="left" valign="top">&bull; <a href="Invoking-G_002b_002b.html#Invoking-G_002b_002b" accesskey="3">Invoking G++</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">Compiling C++ programs.
  136. </td></tr>
  137. <tr><td align="left" valign="top">&bull; <a href="C-Dialect-Options.html#C-Dialect-Options" accesskey="4">C Dialect Options</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">Controlling the variant of C language compiled.
  138. </td></tr>
  139. <tr><td align="left" valign="top">&bull; <a href="C_002b_002b-Dialect-Options.html#C_002b_002b-Dialect-Options" accesskey="5">C++ Dialect Options</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">Variations on C++.
  140. </td></tr>
  141. <tr><td align="left" valign="top">&bull; <a href="Objective_002dC-and-Objective_002dC_002b_002b-Dialect-Options.html#Objective_002dC-and-Objective_002dC_002b_002b-Dialect-Options" accesskey="6">Objective-C and Objective-C++ Dialect Options</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">Variations on Objective-C
  142. and Objective-C++.
  143. </td></tr>
  144. <tr><td align="left" valign="top">&bull; <a href="Diagnostic-Message-Formatting-Options.html#Diagnostic-Message-Formatting-Options" accesskey="7">Diagnostic Message Formatting Options</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">Controlling how diagnostics should
  145. be formatted.
  146. </td></tr>
  147. <tr><td align="left" valign="top">&bull; <a href="Warning-Options.html#Warning-Options" accesskey="8">Warning Options</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">How picky should the compiler be?
  148. </td></tr>
  149. <tr><td align="left" valign="top">&bull; <a href="Debugging-Options.html#Debugging-Options" accesskey="9">Debugging Options</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">Producing debuggable code.
  150. </td></tr>
  151. <tr><td align="left" valign="top">&bull; <a href="Optimize-Options.html#Optimize-Options">Optimize Options</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">How much optimization?
  152. </td></tr>
  153. <tr><td align="left" valign="top">&bull; <a href="Instrumentation-Options.html#Instrumentation-Options">Instrumentation Options</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">Enabling profiling and extra run-time error checking.
  154. </td></tr>
  155. <tr><td align="left" valign="top">&bull; <a href="Preprocessor-Options.html#Preprocessor-Options">Preprocessor Options</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">Controlling header files and macro definitions.
  156. Also, getting dependency information for Make.
  157. </td></tr>
  158. <tr><td align="left" valign="top">&bull; <a href="Assembler-Options.html#Assembler-Options">Assembler Options</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">Passing options to the assembler.
  159. </td></tr>
  160. <tr><td align="left" valign="top">&bull; <a href="Link-Options.html#Link-Options">Link Options</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">Specifying libraries and so on.
  161. </td></tr>
  162. <tr><td align="left" valign="top">&bull; <a href="Directory-Options.html#Directory-Options">Directory Options</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">Where to find header files and libraries.
  163. Where to find the compiler executable files.
  164. </td></tr>
  165. <tr><td align="left" valign="top">&bull; <a href="Code-Gen-Options.html#Code-Gen-Options">Code Gen Options</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">Specifying conventions for function calls, data layout
  166. and register usage.
  167. </td></tr>
  168. <tr><td align="left" valign="top">&bull; <a href="Developer-Options.html#Developer-Options">Developer Options</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">Printing GCC configuration info, statistics, and
  169. debugging dumps.
  170. </td></tr>
  171. <tr><td align="left" valign="top">&bull; <a href="Submodel-Options.html#Submodel-Options">Submodel Options</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">Target-specific options, such as compiling for a
  172. specific processor variant.
  173. </td></tr>
  174. <tr><td align="left" valign="top">&bull; <a href="Spec-Files.html#Spec-Files">Spec Files</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">How to pass switches to sub-processes.
  175. </td></tr>
  176. <tr><td align="left" valign="top">&bull; <a href="Environment-Variables.html#Environment-Variables">Environment Variables</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">Env vars that affect GCC.
  177. </td></tr>
  178. <tr><td align="left" valign="top">&bull; <a href="Precompiled-Headers.html#Precompiled-Headers">Precompiled Headers</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">Compiling a header once, and using it many times.
  179. </td></tr>
  180. </table>
  181. <hr>
  182. <div class="header">
  183. <p>
  184. Next: <a href="C-Implementation.html#C-Implementation" accesskey="n" rel="next">C Implementation</a>, Previous: <a href="Standards.html#Standards" accesskey="p" rel="prev">Standards</a>, Up: <a href="index.html#Top" accesskey="u" rel="up">Top</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Option-Index.html#Option-Index" title="Index" rel="index">Index</a>]</p>
  185. </div>
  186. </body>
  187. </html>