]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/doc/gcc/gcc-command-options/compiling-c++-programs.rst
sphinx: add missing trailing newline
[thirdparty/gcc.git] / gcc / doc / gcc / gcc-command-options / compiling-c++-programs.rst
CommitLineData
c63539ff
ML
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
10Compiling C++ Programs
11**********************
12
13C++ 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
17preprocessed C++ files use the suffix :samp:`.ii`. GCC recognizes
18files with these names and compiles them as C++ programs even if you
19call the compiler the same way as for compiling C programs (usually
20with the name :command:`gcc`).
21
22.. index:: g++, c++
23
24However, the use of :command:`gcc` does not add the C++ library.
25:command:`g++` is a program that calls GCC and automatically specifies linking
26against the C++ library. It treats :samp:`.c`,
27:samp:`.h` and :samp:`.i` files as C++ source files instead of C source
28files unless :option:`-x` is used. This program is also useful when
29precompiling a C header file with a :samp:`.h` extension for use in C++
30compilations. On many systems, :command:`g++` is also installed with
31the name :command:`c++`.
32
33.. index:: invoking g++
34
35When you compile C++ programs, you may specify many of the same
36command-line options that you use for compiling programs in any
37language; or command-line options meaningful for C and related
38languages; or options that are meaningful only for C++ programs.
39See :ref:`c-dialect-options`, for
40explanations of options for languages related to C.
41See :ref:`c++-dialect-options`, for
3ed1b4ce 42explanations of options that are meaningful only for C++ programs.