2016-10-20 90 views
3

我想用MingW在windows上編寫C++ Qt崩潰報告。我參考了https://spin.atomicobject.com/2013/01/13/exceptions-stack-traces-c/ ,但我的代碼不能編譯並給出以下錯誤 - 我在Qt 5.4.0 mingw的Windows 10上使用此代碼。編譯此代碼時出現一些錯誤。 錯誤:未定義參照[email protected]′ error: undefined reference to _imp__SymGetModuleBase @ 8' 錯誤:未定義參照[email protected]′ error: undefined reference to _imp__StackWalk @ 36' 錯誤:未定義參考`_imp__SymCleanup @ 4'Windows上的C++ Mingw崩潰報告

這些錯誤是從下面的代碼。

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負責上述功能。 有人可以告訴我如何解決這種類型的錯誤。

在此先感謝。

回答

3

看起來好像您沒有將imagehlp.lib導入庫添加到您的構建中?即將其添加到其他平臺庫列表中。如果你不得不爲<imagehlp.h>添加包含路徑,那麼你可能會在同級目錄中找到imagehlp.lib

+0

我做到了。但仍然是相同的錯誤。有沒有什麼辦法來檢查它需要哪個版本的dll。因爲我正在使用Windows 10 64位機器,並且系統已經在system32等許多文件夾中有很多imagehlp.dll。 – Abhi

+0

ImageHlp經歷了許多版本,並且使用其他工具進行了很多重新分發。然而,特定的DLL還沒有(你)的問題,因爲它無法鏈接導入庫(.lib)。它看起來好像是在編譯32位x86,但可能選擇了64位DLL的導入庫 - 我有兄弟目錄「\ x32 \ ImageHlp.Lib」和「\ x64 \ ImageHlp.Lib」。 –

0

Mingw64具有直接鏈接到dll的功能,它比msvc導入庫更慢一些,但不容易出錯,這似乎與最近的mingw64不兼容的次數多於不是。確保dll被列爲目標(或者-L -limagehlp,如果有效的話)所有依賴它的對象/源。