Compiling C++ Programs#
C++ source files conventionally use one of the suffixes
.cxx; C++ header files often use
.H, or (for shared template code)
preprocessed C++ files use the suffix
.ii. 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 gcc).
However, the use of gcc does not add the C++ library.
g++ is a program that calls GCC and automatically specifies linking
against the C++ library. It treats
.i files as C++ source files instead of C source
-x is used. This program is also useful when
precompiling a C header file with a
.h extension for use in C++
compilations. On many systems, g++ is also installed with
the name c++.
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 Options Controlling C Dialect, for explanations of options for languages related to C. See Options Controlling C++ Dialect, for explanations of options that are meaningful only for C++ programs.