1
2
3
4
5
6
|
<div class="section-level-extent" id="Invoking-G_002b_002b"> <div class="nav-panel"> <p> Next: <a href="c-dialect-options" accesskey="n" rel="next">Options Controlling C Dialect</a>, Previous: <a href="overall-options" accesskey="p" rel="prev">Options Controlling the Kind of Output</a>, Up: <a href="invoking-gcc" accesskey="u" rel="up">GCC Command Options</a> [<a href="index#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="indices" title="Index" rel="index">Index</a>]</p> </div> <h1 class="section" id="Compiling-C_002b_002b-Programs"><span>3.3 Compiling C++ Programs<a class="copiable-link" href="#Compiling-C_002b_002b-Programs"> ¶</a></span></h1> <p>C++ source files conventionally use one of the suffixes ‘<samp class="samp">.C</samp>’, ‘<samp class="samp">.cc</samp>’, ‘<samp class="samp">.cpp</samp>’, ‘<samp class="samp">.CPP</samp>’, ‘<samp class="samp">.c++</samp>’, ‘<samp class="samp">.cp</samp>’, or ‘<samp class="samp">.cxx</samp>’; C++ header files often use ‘<samp class="samp">.hh</samp>’, ‘<samp class="samp">.hpp</samp>’, ‘<samp class="samp">.H</samp>’, or (for shared template code) ‘<samp class="samp">.tcc</samp>’; and preprocessed C++ files use the suffix ‘<samp class="samp">.ii</samp>’. GCC recognizes files with these names and compiles them as C++ programs even if you call the compiler the same way as for compiling C programs (usually with the name <code class="command">gcc</code>). </p> <p>However, the use of <code class="command">gcc</code> does not add the C++ library. <code class="command">g++</code> is a program that calls GCC and automatically specifies linking against the C++ library. It treats ‘<samp class="samp">.c</samp>’, ‘<samp class="samp">.h</samp>’ and ‘<samp class="samp">.i</samp>’ files as C++ source files instead of C source files unless <samp class="option">-x</samp> is used. This program is also useful when precompiling a C header file with a ‘<samp class="samp">.h</samp>’ extension for use in C++ compilations. On many systems, <code class="command">g++</code> is also installed with the name <code class="command">c++</code>. </p> <p>When you compile C++ programs, you may specify many of the same command-line options that you use for compiling programs in any language; or command-line options meaningful for C and related languages; or options that are meaningful only for C++ programs. See <a class="xref" href="c-dialect-options">Options Controlling C Dialect</a>, for explanations of options for languages related to C. See <a class="xref" href="c_002b_002b-dialect-options">Options Controlling C++ Dialect</a>, for explanations of options that are meaningful only for C++ programs. </p> </div> <div class="nav-panel"> <p> Next: <a href="c-dialect-options">Options Controlling C Dialect</a>, Previous: <a href="overall-options">Options Controlling the Kind of Output</a>, Up: <a href="invoking-gcc">GCC Command Options</a> [<a href="index#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="indices" title="Index" rel="index">Index</a>]</p> </div><div class="_attribution">
<p class="_attribution-p">
© Free Software Foundation<br>Licensed under the GNU Free Documentation License, Version 1.3.<br>
<a href="https://gcc.gnu.org/onlinedocs/gcc-13.1.0/gcc/Invoking-G_002b_002b.html" class="_attribution-link">https://gcc.gnu.org/onlinedocs/gcc-13.1.0/gcc/Invoking-G_002b_002b.html</a>
</p>
</div>
|