【问题标题】:Crash Report in C++ Mingw on windowsWindows 上 C++ Mingw 中的崩溃报告
【发布时间】:2016-10-20 05:48:58
【问题描述】:

我正在尝试使用 MingW 在 Windows 上用 c++ Qt 编写崩溃报告。我参考了https://spin.atomicobject.com/2013/01/13/exceptions-stack-traces-c/ 但我的代码无法编译并给出以下错误- 我在带有 Qt 5.4.0 mingw 的 Windows 10 上使用此代码。我在编译这段代码时遇到了一些错误。 错误:未定义引用_imp__SymInitialize@12′ error: undefined reference to_imp__SymGetModuleBase@8′ 错误:未定义对_imp__SymFunctionTableAccess@8′ error: undefined reference to_imp__StackWalk@36' 的引用 错误:未定义对`_imp__SymCleanup@4′的引用

这些错误来自以下代码。

void windows_print_stacktrace(CONTEXT* context)
{
  SymInitialize(GetCurrentProcess(), 0, true);

  STACKFRAME frame = { 0 };

  /* setup initial stack frame */
  frame.AddrPC.Offset         = context->Eip;
  frame.AddrPC.Mode           = AddrModeFlat;
  frame.AddrStack.Offset      = context->Esp;
  frame.AddrStack.Mode        = AddrModeFlat;
  frame.AddrFrame.Offset      = context->Ebp;
  frame.AddrFrame.Mode        = AddrModeFlat;

  while (StackWalk(IMAGE_FILE_MACHINE_I386 ,
                   GetCurrentProcess(),
                   GetCurrentThread(),
                   &frame,
                   context,
                   0,
                   SymFunctionTableAccess,
                   SymGetModuleBase,
                   0 ) )
  {
    addr2line(icky_global_program_name, (void*)frame.AddrPC.Offset);
  }

  SymCleanup( GetCurrentProcess() );
}

imagehlp.dll 负责上述功能。 谁能告诉我如何解决此类错误。

提前致谢。

【问题讨论】:

    标签: c++ c windows qt mingw


    【解决方案1】:

    您好像没有将imagehlp.lib 导入库添加到您的构建中?即将它添加到其他平台库的列表中。如果您必须为 <imagehlp.h> 添加包含路径,那么您可能会在同级目录中找到 imagehlp.lib

    【讨论】:

    • 我做到了。但仍然是同样的错误。有没有办法检查它需要哪个版本的dll。因为我正在使用 Windows 10 64 位机器,并且系统已经在 system32 等许多文件夹中有许多 imagehlp.dll。
    • ImageHlp 经历了许多版本,并且确实与其他工具一起重新分发了很多。但是,特定的 DLL(还)不是您的问题,因为它无法链接导入库 (.lib)。看起来好像您正在为 32 位 x86 进行编译,但可能已经为 64 位 DLL 选择了导入库 - 我将“\x32\ImageHlp.Lib”和“\x64\ImageHlp.Lib”作为同级目录。
    【解决方案2】:

    Mingw64 具有直接链接到 dll 的能力,这比 msvc 导入库慢一点,但更不容易出错 - 这似乎与最近的 mingw64 不兼容更多次。确保 dll 被列为目标(如果可行,则列为 -L -limagehlp)所有依赖它的对象/源之后。

    【讨论】:

      猜你喜欢
      • 2011-07-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-11
      • 2022-10-14
      • 2020-06-14
      • 2023-04-06
      • 2013-02-06
      相关资源
      最近更新 更多