bombela / backward-cpp

A beautiful stack trace pretty printer for C++
MIT License
3.66k stars 466 forks source link

using "backward" in Windows OS #320

Closed kondrahin241996 closed 7 months ago

kondrahin241996 commented 7 months ago

Hello. I have a small issue with connecting the header library "backward". I have successfully connected "backward under Linux. I also connected the elfutils library. I built it using the make utility. I'm getting a trace.

I would really like to use "backward" to output stack traces under Windows OS as well. At the moment, I have added a file.hpp as src. Before the main function, I wrote the following code:

#include "backward.hpp"
#define BACKWARD_HAS_DW 1
namespace backward {
backward::SignalHandling sh;
} // namespace backward

I am building and compiling in the "Debug" mode. But when the program starts, the trace is not displayed. Can you help me with connecting this header library to the Visual Studio environment in Windows? Which connection algorithm should I reproduce?

bombela commented 7 months ago

Note that #define BACKWARD_HAS_DW 1 must be defined before #include "backward.hpp". And you would then also need to link with the dw library. But this is specific to UNIX, and doesn't apply to MS Windows.

For MS Windows see for reference https://github.com/bombela/backward-cpp/blob/master/BackwardConfig.cmake#L204 and https://github.com/bombela/backward-cpp/blob/master/backward.hpp#L361. By default it should just work.

backward::SignalHandling sh; will only print a trace when a signal is raise (including on un-handled exception). You can read the documentation (https://github.com/bombela/backward-cpp#stacktrace) for printing traces on demand.

kondrahin241996 commented 7 months ago

Did I understand correctly that the link #L204 to generate my project via cmake? If I don't use cmake and just attach the file .hpp, then should everything work?

bombela commented 7 months ago

Yes it should just work. The header has pragmas to link with the right libraries on msvc.

On Sat, Dec 2, 2023, 07:06 paul3 @.***> wrote:

Did I understand correctly that the link #L204 to generate my project via Cmake? If I don't use cmake and just attach the file .hpp, then should everything work?

— Reply to this email directly, view it on GitHub https://github.com/bombela/backward-cpp/issues/320#issuecomment-1837055306, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABUZDDHJSTSA3WIJHMOVZLYHLAPVAVCNFSM6AAAAABADBORBGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQMZXGA2TKMZQGY . You are receiving this because you commented.Message ID: @.***>

kondrahin241996 commented 7 months ago

Thank you very much for the quick response! You've helped me a lot.