c++23 building with <stacktrace> library

577 views Asked by At

I'm trying to use "stacktrace" library from my c++ project. https://en.cppreference.com/w/cpp/header/stacktrace

I'm using GCC 13 and CPP standard 23.

In my cmake file, I am adding target_link_libraries([Target] stdc++_libbacktrace)

If I compile, I get the following error.

compile_utils.cpp:10:34: error: ‘std::stacktrace’ has not been declared
   10 |     const auto stacktrace = std::stacktrace::current();

Also I tried to enable the following flag via set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --enable-libstdcxx-backtrace") But then I get the following cmake build error cc1plus: error: unknown pass libstdcxx-backtrace specified in ‘-fenable’

How can I resolve the above errors?

Thank you very much!

// Usage

#include <stacktrace>

void test()
{
    const auto stacktrace = std::stacktrace::current();
    const auto strStackTrace = stacktrace.to_string();    
}

// Just in case, using "Ubuntu 22.04.3 LTS"

// Just in case, tried target_link_libraries([Target] stdc++exp) too but no luck

https://gcc.gnu.org/onlinedocs/gcc-13.2.0/libstdc++/manual/manual/using.html#manual.intro.using.flags

1

There are 1 answers

0
Terryn On

Not sure if this got answered (and I'd love to see how you solved it if it did) But it appears if you have installed G++13 through just an apt-get install g++-13, this doesn't have stacktrace enabled:

<bits/c++config.h>

/* Define if the <stacktrace> header is supported. */
/* #undef _GLIBCXX_HAVE_STACKTRACE */

Unless there's some other solution, it appears the default build doesn't support stacktrace. I would note that I am doing this through an arm-ubuntu23.04 image, and it may also be an arm thing, I would defer to someone who may know a bit more about th