g++ - GNU project C++ Compiler


g++ __[__''option''?...


The C and C++ compilers are integrated; g++ is a script to call gcc with options to recognize C++. gcc processes input files through one or more of four stages: preprocessing, compilation, assembly, and linking. This man page contains full descriptions for only C++ specific aspects of the compiler, though it also contains summaries of some general-purpose options. For a fuller explanation of the compiler, see gcc(1).

C++ source files use one of the suffixes `.C', `.cc', `.cxx', `.cpp', or `.c++'; preprocessed C++ files use the suffix `.ii'.


There are many command-line options, including options to control details of optimization, warnings, and code generation, which are common to both gcc and g++. For full information on all options, see gcc(1).








Define macro macro as defn.







Permit the use of `$' in identifiers. Traditional C allowed the character `$' to form part of identifiers; by default, GNU C also allows this. However, ANSI C forbids `$' in identifiers, and GNU C++ also forbids it by default on most platforms (though on some platforms it's enabled by default for GNU C++ as well).


Use this option to instruct the compiler to be smarter about when it can elide constructors. Without this flag, GNU C++ and cfront both generate effectively the same code for:

A foo (); A x (foo ()); // x initialized by `foo ()', no ctor called A y = foo (); // call to `foo ()' heads to temporary, // y is initialized from the temporary.

Note the difference! With this flag, GNU C++ initializes `y' directly from the call to foo () without going through a temporary.


Normally GNU C++ allows conversion of enum to int, but not the other way around. Use this option if you want GNU C++ to allow conversion of int to enum as well.


Produce smaller code for template declarations, by generating only a single copy of each template function where it is defined. To use this option successfully, you must also mark all files that use templates with either `#pragma implementation' (the definition) or `#pragma interface' (declarations).






These flags are used to get the compiler to compile programs faster using heuristics. They are not on by default since they are only effective about half the time. The other half of the time programs compile more slowly (and take more memory).






Do not make member functions inline by default merely because they are defined inside the class scope. Otherwise, when you specify -O, member functions defined inside class scope are compiled inline by default; i.e., you don't need to add `inline' in front of the member function name.


Consider the declaration int foo ();. In C++, this means that the function foo takes no arguments. In ANSI C, this is declared int foo(void);. With the flag `-fno-strict-prototype', declaring functions with no arguments is equivalent to declaring its argument list to be untyped, i.e., int foo (); is equivalent to saying int foo (...);.


Normally, GNU C++ makes conservative assumptions about objects reached through references. For example, the compiler must check that `a' is not null in code like the following: obj a.f (2); Checking that references of this sort have non-null values requires extra code, however, and it is unnecessary for many programs. You can use `-fnonnull-objects' to omit the checks for null, if your program doesn't require the default checking.



These options control the recognition of the signature and sigof constructs for specifying abstract types. By default, these constructs are not recognized.


The incorporation of user-defined free store management into C++ has made assignment to this an anachronism. Therefore, by default GNU C++ treats the type of this in a member function of class X to be __X

  • const__. In other words, it is illegal to assign to

this within a class member function. However, for backwards compatibility, you can invoke the old behavior by using `-fthis-is-variable'.


Produce debugging information in the operating system's native format (for DBX or SDB or DWARF). GDB also can work with this debugging information. On most systems that use DBX format, `-g' enables use of extra debugging information that only GDB can use.








Use the library named library when linking. (C++ programs often require `-lg++' for successful linking.)


Do not search the standard system directories for header files. Only the directories you have specified with -I options (and the current directory, if appropriate) are searched.


Do not search for header files in the standard directories specific to C++, but do still search the other standard directories. (This option is used when building libg++.)



-o file

Place output in file file.




Attempt to support some aspects of traditional C compilers.

Specifically, for both C and C++ programs:

In the preprocessor, comments convert to nothing at all, rather than to a space. This allows traditional token concatenation.

In the preprocessor, macro arguments are recognized within string constants in a macro definition (and their values are stringified, though without additional quote marks, when they appear in such a context). The preprocessor always considers a string constant to end at a newline.

The preprocessor does not predefine the macro STDC when you use `-traditional', but still predefinesGNUC (since the GNU extensions indicated by GNUC are not affected by `-traditional'). If you need to write header files that work differently depending on whether `-traditional' is in use, by testing both of these predefined macros you can distinguish four situations: GNU C, traditional GNU C, other ANSI C compilers, and other old C compilers.

String ``constants'' are not necessarily constant; they are stored in writable space, and identical looking constants are allocated separately.

For C++ programs only (not C), `-traditional' has one additional effect: assignment to this is permitted. This is the same as the effect of `-fthis-is-variable'.


Undefine macro macro.


Issue warnings for conditions which pertain to usage that we recommend avoiding and that we believe is easy to avoid, even in conjunction with macros.


Warn when converting between different enumeration types.






Inhibit all warning messages.


Control how virtual function definitions are used, in a fashion compatible with cfront 1.x.



#pragma interface


#pragma implementation

#pragma implementation objects.h


If you use `#pragma implementation' with no argument, it applies to an include file with the same basename as your source file; for example, in `', `#pragma implementation' by itself is equivalent to `#pragma implementation '. Use the string argument if you want a single implementation file to include code from multiple header files.



file.h C header (preprocessor) file file.i preprocessed C source file file.C C++ source file C++ source file file.cxx C++ source file file.s assembly language file file.o object file a.out link edited output TMPDIR/cc temporary files LIBDIR/cpp preprocessor LIBDIR/cc1plus compiler LIBDIR/collect linker front end needed on some machines LIBDIR/libgcc.a GCC subroutine library /lib/crt[01n?.o start-up routine LIBDIR/ccrt0 additional start-up routine for C++ /lib/libc.a standard C library, see intro(3) /usr/include standard directory for #include files LIBDIR/include standard gcc directory for #include files LIBDIR/g++-include additional g++ directory for #include

LIBDIR is usually /usr/local/lib/machine/version. TMPDIR comes from the environment variable TMPDIR (default /usr/tmp if available, else /tmp).


gcc(1), cpp(1), as(1), ld(1), gdb(1), adb(1)?, dbx(1)?, sdb(1)?. `gcc', `cpp', `as',`ld', and `gdb' entries in info. Using and Porting GNU CC (for version 2.0), Richard M. Stallman; The C Preprocessor, Richard M. Stallman; Debugging with GDB: the GNU Source-Level Debugger, Richard M. Stallman and Roland H. Pesch; Using as: the GNU Assembler, Dean Elsner, Jay Fenlason gld: the GNU linker, Steve Chamberlain and Roland Pesch.









See the GNU CC Manual for the contributors to GNU CC.
