Chapter 3. Using

Table of Contents

Command Options
Header Files
Mixing Headers
The C Headers and namespace std
Precompiled Headers
Dual ABI
Available Namespaces
namespace std
Using Namespace Composition
Almost Nothing
Finding Dynamic or Shared Libraries
Experimental Library Extensions
Thread Safety
Exception Safety
Exception Neutrality
Memory allocation
Doing without
With C
With POSIX thread cancellation
Debugging Support
Using g++
Debug Mode
Tracking uncaught exceptions
Memory Leak Hunting
Non-memory leaks in Pool and MT allocators
Data Race Hunting
Using gdb
Debug Versions of Library Binary Files
Compile Time Checking

Command Options

The set of features available in the GNU C++ library is shaped by several GCC Command Options. Options that impact libstdc++ are enumerated and detailed in the table below.

The standard library conforms to the dialect of C++ specified by the -std option passed to the compiler. By default, g++ is equivalent to g++ -std=gnu++17 since GCC 11, and g++ -std=gnu++14 in GCC 6, 7, 8, 9, and 10, and g++ -std=gnu++98 for older releases.

Table 3.1. C++ Command Options

Option FlagsDescription
-std=c++98 or -std=c++03 Use the 1998 ISO C++ standard plus amendments.
-std=gnu++98 or -std=gnu++03 As directly above, with GNU extensions.
-std=c++11Use the 2011 ISO C++ standard.
-std=gnu++11As directly above, with GNU extensions.
-std=c++14Use the 2014 ISO C++ standard.
-std=gnu++14As directly above, with GNU extensions.
-fno-exceptions See exception-free dialect
-fno-rtti As above, but RTTI-free dialect.
-pthreadFor ISO C++11 <thread>, <future>, <mutex>, or <condition_variable>.
-latomicLinking to libatomic is required for some uses of ISO C++11 <atomic>.
-lstdc++expLinking to libstdc++exp.a is required for use of experimental C++ library features. This currently provides support for the C++23 types defined in the <stacktrace> header, the Filesystem library extensions defined in the <experimental/filesystem> header, and the Contracts extensions enabled by -fcontracts.
-lstdc++fsLinking to libstdc++fs.a is another way to use the Filesystem library extensions defined in the <experimental/filesystem> header. The libstdc++exp.a library also provides all the symbols contained in this library.
-fopenmpFor parallel mode.
-ltbbLinking to tbb (Thread Building Blocks) is required for use of the Parallel Standard Algorithms and execution policies in <execution>.
-ffreestanding Limits the library to its freestanding subset. Headers that are not supported in freestanding will emit a "This header is not available in freestanding mode" error. Headers that are in the freestanding subset partially will not expose functionality that is not part of the freestanding subset.