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位構建中,兩種變體的工作方式都是相同的。
謝謝。解決了在我的CMakeLists.txt問題中使用pkg-config中的libtorrent build cfalgs之後。 –