Boost::Stacktrace minimal example
main.cpp
#include <boost/stacktrace.hpp>
#include <iostream>
void foo();
void bar() {
// Capture and print the current stacktrace
std::cout << "Stacktrace:\n" << boost::stacktrace::stacktrace() << std::endl;
}
void foo() {
bar();
}
int main() {
foo();
return 0;
}
How to compile
g++ -g main.cpp -std=c++17 -rdynamic -lboost_stacktrace_basic -o app
Example output
$ ./app
Stacktrace:
0# bar() in ./app
1# foo() in ./app
2# main in ./app
3# 0x000072C53AE2A1CA in /lib/x86_64-linux-gnu/libc.so.6
4# __libc_start_main in /lib/x86_64-linux-gnu/libc.so.6
5# _start in ./app
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow