LinuxCommandLibrary

g++

GNU C++ compiler

TLDR

Compile C++ file

$ g++ [source.cpp] -o [output]
copy
Compile with warnings
$ g++ -Wall -Wextra [source.cpp] -o [output]
copy
Compile with optimization
$ g++ -O2 [source.cpp] -o [output]
copy
Debug build
$ g++ -g [source.cpp] -o [output]
copy
Compile with C++ standard
$ g++ -std=c++17 [source.cpp] -o [output]
copy

SYNOPSIS

g++ [options] files...

DESCRIPTION

g++ is the GNU C++ compiler, part of the GNU Compiler Collection. It compiles C++ source code to executables or object files, supporting modern C++ standards.
The compiler handles preprocessing, compilation, assembly, and linking. It provides extensive optimization options and warning controls for quality code production.
g++ is the standard C++ compiler on Linux systems, supporting the full range of C++ language features.

PARAMETERS

FILES

Source files to compile.
-o FILE
Output filename.
-c
Compile only, no linking.
-Wall
Enable all warnings.
-g
Generate debug info.
-O LEVEL
Optimization level (0-3, s, fast).
-std STANDARD
C++ standard (c++11, c++14, c++17, c++20).
-I PATH
Include path.
-L PATH
Library path.
-l LIBRARY
Link library.
--help
Display help information.

CAVEATS

Large codebases compile slowly. Template errors can be cryptic. Different standards have different feature sets.

HISTORY

g++ is part of GCC (GNU Compiler Collection), originally written by Richard Stallman. It evolved from the original GNU C Compiler to support multiple languages including C++.

SEE ALSO

gcc(1), clang++(1), make(1)

> TERMINAL_GEAR

Curated for the Linux community

Copied to clipboard