Skip to content
Latchkey

g++: Usage, Options & Common CI Errors

g++ compiles and links C++ with the correct standard library defaults.

g++ is gcc configured for C++: it links libstdc++ automatically and defaults to a recent -std. The CI traps are forgetting -std, the vtable/undefined-reference symptom of an unimplemented virtual, and the C++11 ABI split.

What it does

g++ is the C++ front-end of GCC. Unlike gcc it links the C++ standard library (libstdc++) by default and treats inputs as C++. It compiles, assembles, and links C++ translation units into objects and executables.

Common usage

Terminal
g++ -std=c++17 -Wall -O2 main.cpp -o app
g++ -c util.cpp -o util.o                    # compile only
g++ main.o util.o -o app -lpthread
g++ -std=c++20 -g main.cpp -o app            # debug
g++ -fsanitize=address -g main.cpp -o app    # ASan build

Options

FlagWhat it does
-std=c++17|c++20|c++23Select the C++ language standard
-c / -o <file>Compile only / name output
-pthreadCompile+link with POSIX threads
-l<name> -L<dir>Link a library / add lib path
-fsanitize=address|undefinedEnable a sanitizer
-Wall -Wextra -WerrorWarnings; -Werror is fatal

Common errors in CI

"undefined reference to vtable for X" usually means a class has a non-pure virtual with no definition (often the first non-inline virtual / destructor) - define it. "error: ‘std::make_unique’ was not declared" means the -std is too old; add -std=c++14 or newer. The dual ABI bite: objects built with the pre-C++11 std::string ABI fail to link against new ones - keep _GLIBCXX_USE_CXX11_ABI consistent across all objects and prebuilt libs.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →