Search code examples
c++linuxg++c++23

How can I generate a C++23 stacktrace with GCC 12.1?


In the release notes for GCC12, under the section "Runtime Library (libstdc++)", it says:

Improved experimental C++23 support, including: [...] <stacktrace> (not built by default, requires linking to an extra library).

What library do I need to link against to use <stacktrace>? I'm on an x86 Linux system, if that matters.


Solution

  • You need to link with -lstdc++_libbacktrace (as documented here). Note that since GCC14, you should use -lstdc++exp instead (as documented here).

    In order for this to work, gcc needs to have been configured with --enable-libstdcxx-backtrace.