2013-11-24 47 views
0

我想在我的Qt5應用程序中使用libtorrent,但不斷收到像malloc()這樣的消息的段錯誤 :內存損壞。後debbuging小時我想出這個小塊代碼觸發此問題:libtorrent-rasterbar和QGuiApplication的內存損壞

int main(int argc, char *argv[]) 
{ 
    QGuiApplication app(argc, argv); 
    std::string filename = "fedora.torrent"; 
    libtorrent::error_code ec; 
    libtorrent::add_torrent_params parameters; 
    std::cerr << "111\n"; 
    parameters.ti = new libtorrent::torrent_info(filename, ec);; 
    std::cerr << "222\n"; 
    return app.exec() 
} 

在torrent_info產生段錯誤這種情況下的構造。但是,如果我創造QGuiApplication之前移動libtorrent相關的代碼是這樣的:

int main(int argc, char *argv[]) 
{ 
    std::string filename = "fedora.torrent"; 
    libtorrent::error_code ec; 
    libtorrent::add_torrent_params parameters; 
    std::cerr << "111\n"; 
    parameters.ti = new libtorrent::torrent_info(filename, ec);; 
    std::cerr << "222\n"; 
    QGuiApplication app(argc, argv); 
    return app.exec() 
} 

然後它工作得很好。此外,這個問題只存在於32位構建中,在64位構建中,兩種變體的工作方式都是相同的。

回答

1

這很可能是由於通過構建一組TORRENT_ *來構建libtorrent *,並使用不同的集合來定義和鏈接它。其中一些定義會影響公共API中使用的某些結構的佈局,並且調用應用程序和庫之間的差異會引入ABI不兼容問題。

+0

謝謝。解決了在我的CMakeLists.txt問題中使用pkg-config中的libtorrent build cfalgs之後。 –