https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111936
--- Comment #1 from vincenzo Innocente <vincenzo.innocente at cern dot ch> --- here is a minimal malloc hook that I would like to use [innocent@patatrack01 ctest]$ cat getStacktrace.cc #include <stacktrace> std::string get_stacktrace() { std::string trace; for (auto & entry : std::stacktrace::current() ) trace += entry.description() + '#'; return trace; } #include <cstdlib> #include <malloc.h> #include <iostream> extern "C" void * myMallocHook(size_t size, void const * caller) { __malloc_hook = nullptr; auto p = malloc(size); std::cout << "asked " << size << " at " << get_stacktrace() << std::endl; __malloc_hook = myMallocHook; return p; } namespace { struct Hook { Hook() { __malloc_hook = myMallocHook; } }; Hook hook; } compiled as c++ -O3 -Wall -pthread -fPIC -shared -std=c++23 -lstdc++exp getStacktrace.cc gives the undefined symbol setenv LD_PRELOAD ./a.out ; ls ; unsetenv LD_PRELOAD ls: symbol lookup error: ./a.out: undefined symbol: _ZNSt17__stacktrace_impl10_S_currentEPFiPvmES0_i