Boost stack-trace not showing function names and line numbers

You need to do a few things (this is for Linux):

  1. Make sure that debug info is enabled: e.g., -g

  2. Link against libdl: -ldl

  3. Define one of the necessary macros (to get line numbers): e.g., -DBOOST_STACKTRACE_USE_ADDR2LINE

All this info is provided here:

https://www.boost.org/doc/libs/1_69_0/doc/html/stacktrace/configuration_and_build.html


I do not have enough reputation to comment, so I'll extend jordi's answer here:

  1. Make sure that debug info is enabled: e.g., -g

  2. Link against libdl: -ldl

  3. Define one of the necessary macros (to get line numbers): e.g., -DBOOST_STACKTRACE_USE_ADDR2LINE

  4. Compile and link with -no-pie and -fno-pie options.


This worked for me:

g++ -g backtrace.cpp -o bb -lboost_stacktrace_backtrace -D BOOST_STACKTRACE_LINK

-D BOOST_STACKTRACE_LINK was the missing option that solved the problem for me.


This is what worked for me, I am compiling with g++ :

  • Compile with -g -ggdb -no-pie -fno-pie -rdynamic
  • define macro -DBOOST_STACKTRACE_USE_ADDR2LINE
  • Link against libdl -libl and -no-pie -fno-pie

Edit : in my case rdynamic was the missing bit to allow me to have unmagled function names and line numbers