]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/doc/gcc/gcc-command-options/compiling-c++-programs.rst
sphinx: copy files from texi2rst-generated repository
[thirdparty/gcc.git] / gcc / doc / gcc / gcc-command-options / compiling-c++-programs.rst
1 ..
2 Copyright 1988-2022 Free Software Foundation, Inc.
3 This is part of the GCC manual.
4 For copying conditions, see the copyright.rst file.
5
6 .. index:: suffixes for C++ source, C++ source file suffixes
7
8 .. _invoking-g++:
9
10 Compiling C++ Programs
11 **********************
12
13 C++ source files conventionally use one of the suffixes :samp:`.C`,
14 :samp:`.cc`, :samp:`.cpp`, :samp:`.CPP`, :samp:`.c++`, :samp:`.cp`, or
15 :samp:`.cxx`; C++ header files often use :samp:`.hh`, :samp:`.hpp`,
16 :samp:`.H`, or (for shared template code) :samp:`.tcc`; and
17 preprocessed C++ files use the suffix :samp:`.ii`. GCC recognizes
18 files with these names and compiles them as C++ programs even if you
19 call the compiler the same way as for compiling C programs (usually
20 with the name :command:`gcc`).
21
22 .. index:: g++, c++
23
24 However, the use of :command:`gcc` does not add the C++ library.
25 :command:`g++` is a program that calls GCC and automatically specifies linking
26 against the C++ library. It treats :samp:`.c`,
27 :samp:`.h` and :samp:`.i` files as C++ source files instead of C source
28 files unless :option:`-x` is used. This program is also useful when
29 precompiling a C header file with a :samp:`.h` extension for use in C++
30 compilations. On many systems, :command:`g++` is also installed with
31 the name :command:`c++`.
32
33 .. index:: invoking g++
34
35 When you compile C++ programs, you may specify many of the same
36 command-line options that you use for compiling programs in any
37 language; or command-line options meaningful for C and related
38 languages; or options that are meaningful only for C++ programs.
39 See :ref:`c-dialect-options`, for
40 explanations of options for languages related to C.
41 See :ref:`c++-dialect-options`, for
42 explanations of options that are meaningful only for C++ programs.