Next: Options Controlling C Dialect, Previous: Options Controlling the Kind of Output, Up: GCC Command Options [Contents][Index]
3.3 Compiling C++ Programs ¶
C++ source files conventionally use one of the suffixes ‘.C’,‘.cc’, ‘.cpp’, ‘.CPP’, ‘.c++’, ‘.cp’, or‘.cxx’; C++ header files often use ‘.hh’, ‘.hpp’,‘.H’, or (for shared template code) ‘.tcc’;preprocessed C++ files use the suffix ‘.ii’; and C++20 module interfaceunits sometimes use ‘.ixx’, ‘.cppm’, ‘.cxxm’, ‘.c++m’,or ‘.ccm’.
GCC recognizes files with these names and compiles them as C++ programs even if youcall the compiler the same way as for compiling C programs (usuallywith the name gcc
).
However, the use of gcc
does not add the C++ library.g++
is a program that calls GCC and automatically specifies linkingagainst the C++ library. It treats ‘.c’,‘.h’ and ‘.i’ files as C++ source files instead of C sourcefiles unless -x is used. This program is also useful whenprecompiling a C header file with a ‘.h’ extension for use in C++compilations. On many systems, g++
is also installed withthe name c++
.
When you compile C++ programs, you may specify many of the samecommand-line options that you use for compiling programs in anylanguage; or command-line options meaningful for C and relatedlanguages; or options that are meaningful only for C++ programs.See Options Controlling C Dialect, forexplanations of options for languages related to C.See Options Controlling C++ Dialect, forexplanations of options that are meaningful only for C++ programs.