# g

Tells the compiler to generate a level of debugging information in the object file.

## Syntax

Linux: | -g[n]

macOS: | -g[n]

Windows: | See option Zi, Z7, ZI.

## Arguments

n | Is the level of debugging information to be generated. Possible values are:
0 | Disables generation of symbolic debug information.
1 | Produces minimal debug information for performing stack traces.
2 | Produces complete debug information. This is the same as specifying -g with no n.
3 | Produces extra information that may be useful for some tools.

## Default

-g or -g2 | The compiler produces complete debug information.

## Description

Option -g tells the compiler to generate symbolic debugging information in the object file, which increases the size of the object file.

The compiler does not support the generation of debugging information in assemblable files. If you specify this option, the resulting object file will contain debugging information, but the assemblable file will not.

This option turns off option -O2 and makes option -O0 the default unless option -O2 (or higher) is explicitly specified in the same command line.

Specifying the -g or -O0 option sets the -fno-omit-frame-pointer option. On Linux*, the -debug inline-debug-info option will be enabled by default if you compile with optimizations (option -O2 or higher) and debugging is enabled (option -g).

Specifying the -g or -O0 option sets the -fno-omit-frame-pointer option.

### Note

When option -g is specified, debugging information is generated in the DWARF Version 3 format. Older versions of some analysis tools may require applications to be built with the -gdwarf-2 option to ensure correct operation.

## IDE Equivalent

Visual Studio: None

Eclipse: General > Include Debug Information

Xcode: General > Generate Debug Information

## Alternate Options

Linux: None

Windows: /Zi, /Z7, /ZI

Parent topic: Output, Debug, and Precompiled Header (PCH) Options

## See Also

gdwarf compiler option
Zi, Z7, ZI compiler option
debug (Linux* and macOS*) compiler option