Korean

g++ — C++ compiler

Development / Build / g++.html

BuildOriginalRegistered 2026-10-20T09:00:00+09:00

The C++ front end of GCC; compiles C++ sources into objects or executables.

Basic Information

Command Nameg++
One-line IntroductionThe C++ front end of GCC; compiles C++ sources into objects or executables.
Provided byGCC (GNU Compiler Collection)
Official Documentationhttps://gcc.gnu.org/onlinedocs/
Supported Operating SystemsLinux, macOS, BSD, Windows (separate install)
Installation StatusRequires a package (build-essential or g++)
CategoryBuild and compile (tags: Language toolchain (tags: g++, c++, compile, gcc))

What is this command?

g++ translates C++ sources into machine code, running preprocessing, compilation, assembly and linking in one invocation. Use -c for objects only and -o to name the output.

Be explicit about warnings and optimization. -Wall -Wextra catches problems early, while release builds typically use -O2 and drop debug symbols. Library order is a common cause of link errors.

What problems does it solve?

  • Compiling C++ sources to check behavior quickly
  • Building objects separately for incremental builds
  • Raising warning levels to catch latent bugs
  • Verifying compatibility with a specific standard

Key features

Single-file build

Compile one source into an executable in one step.

  • When to use: Trying examples or small tools
  • What you get: You get a runnable binary immediately.
  • Limitations: Library dependencies are not resolved automatically.

Warnings and standard

Use -Wall -Wextra and -std for quality and compatibility.

  • When to use: Writing portable code
  • What you get: Problems surface at compile time.
  • Limitations: Warnings alone do not fail the build without -Werror.

Separate objects

Create objects with -c and link them at the end.

  • When to use: Incremental builds of larger projects
  • What you get: Only changed files are recompiled.
  • Limitations: You must manage link order and duplicate symbols.

Installation and usage

Check whether it is installed

g++ --version

sudo apt install build-essential # Debian/Ubuntu sudo dnf install gcc-c++ # Fedora

Real-world examples

Compile one file

Enable warnings and produce an executable.

g++ -Wall -Wextra -O2 -std=c++20 main.cpp -o app
./app

Create an object file

Compile only and link later.

g++ -c util.cpp -o util.o
g++ main.o util.o -o app

Link a library

Link a library that is not included by default.

g++ calc.cpp -o calc -lm