0

我正在尝试在我的 Qt5 应用程序中使用 libtorrent,但不断收到诸如 malloc() 之类的消息的段错误:内存损坏。经过数小时的调试,我想出了触发此问题的一小段代码:

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 位版本中,两种变体的工作方式相同。

4

1 回答 1

1

这很可能是由于使用一组TORRENT_* 定义构建 libtorrent 并使用不同的集合链接它而引起的。其中一些定义会影响公共 API 中使用的某些结构的布局,并且当调用应用程序和库之间存在差异时会引入 ABI 不兼容问题。

于 2013-11-25T09:39:20.560 回答