gpt4 book ai didi

c++ - 构建库 libtorrent debian 并将其链接到程序 c++

转载 作者:塔克拉玛干 更新时间:2023-11-03 07:12:26 25 4
gpt4 key购买 nike

我在构建库和链接它们时总是遇到问题,所以我希望有人能帮助我。

我从 here 下载了 libtorrent我按照他们解释的方式 build 了它 herebuilding with autotools部分(跳过步骤 1)。我认为构建过程是成功的,但是当我这样做的时候make check输出是:

============================================================================
Testsuite summary for libtorrent-rasterbar 1.0.5
============================================================================
# TOTAL: 0
# PASS: 0
# SKIP: 0
# XFAIL: 0
# FAIL: 0
# XPASS: 0
# ERROR: 0
============================================================================

也许它应该说:总 X?

我做了一个小程序,其中添加了 #include <libtorrent/session.hpp>当我用 g++ file.cpp -o file 编译时它说libtorrent/session.hpp: No such file or directory .

我是否应该向 g++ 添加一些标志,例如 -lpthread对于其他项目并有这样的想法?

谢谢

更新:使用 sudo apt-get install libtorrent-rasterbar-dev 安装而不构建时并编译我的 main.cpp 文件时出现此错误:

g++ main.cpp -o file
In file included from /usr/include/libtorrent/session.hpp:49:0,
from main.cpp:2:
/usr/include/libtorrent/config.hpp:46:2: error: #error you must define either BOOST_ASIO_SEPARATE_COMPILATION or BOOST_ASIO_DYN_LINK in your project in order for asio's declarations to be correct. If you're linking dynamically against libtorrent, define BOOST_ASIO_DYN_LINK otherwise BOOST_ASIO_SEPARATE_COMPILATION. You can also use pkg-config or boost build, to automatically apply these defines
#error you must define either BOOST_ASIO_SEPARATE_COMPILATION or BOOST_ASIO_DYN_LINK in your project in \

更新 2:

修改了 main.cpp文件在 libtorrent #include 上方添加以下内容指令:

#ifndef BOOST_ASIO_DYN_LINK
#define BOOST_ASIO_DYN_LINK
#endif

但是我遇到了这个问题:

$ g++ main.cpp
/tmp/ccM2ItFb.o: In function `main':
main.cpp:(.text+0x57): undefined reference to `libtorrent::default_storage_constructor(libtorrent::file_storage const&, libtorrent::file_storage const*, std::string const&, libtorrent::file_pool&, std::vector<unsigned char, std::allocator<unsigned char> > const&)'
main.cpp:(.text+0xb9): undefined reference to `libtorrent::session::~session()'
main.cpp:(.text+0x105): undefined reference to `libtorrent::session::~session()'
/tmp/ccM2ItFb.o: In function `__static_initialization_and_destruction_0(int, int)':
main.cpp:(.text+0x162): undefined reference to `boost::system::generic_category()'
main.cpp:(.text+0x16e): undefined reference to `boost::system::generic_category()'
main.cpp:(.text+0x17a): undefined reference to `boost::system::system_category()'
main.cpp:(.text+0x192): undefined reference to `boost::asio::error::get_netdb_category()'
main.cpp:(.text+0x19e): undefined reference to `boost::asio::error::get_addrinfo_category()'
main.cpp:(.text+0x1aa): undefined reference to `boost::asio::error::get_misc_category()'
/tmp/ccM2ItFb.o: In function `boost::asio::error::get_system_category()':
main.cpp (.text._ZN5boost4asio5error19get_system_categoryEv[_ZN5boost4asio5error19get_system_categoryEv]+0x5): undefined reference to `boost::system::system_category()'
/tmp/ccM2ItFb.o: In function `libtorrent::session::session(libtorrent::fingerprint const&, int, unsigned int)':
main.cpp:(.text._ZN10libtorrent7sessionC2ERKNS_11fingerprintEij[_ZN10libtorrent7sessionC5ERKNS_11fingerprintEij]+0x3c): undefined reference to `libtorrent::rel_clocktime_pools_nolog_resolvecountries_deprecated_dht_ext_()'
main.cpp:(.text._ZN10libtorrent7sessionC2ERKNS_11fingerprintEij[_ZN10libtorrent7sessionC5ERKNS_11fingerprintEij]+0x75): undefined reference to `libtorrent::session::init(std::pair<int, int>, char const*, libtorrent::fingerprint const&, int, unsigned int)'
/tmp/ccM2ItFb.o: In function `void boost::checked_delete<libtorrent::torrent_info const>(libtorrent::torrent_info const*)':
main.cpp:(.text._ZN5boost14checked_deleteIKN10libtorrent12torrent_infoEEEvPT_[_ZN5boost14checked_deleteIKN10libtorrent12torrent_infoEEEvPT_]+0x1a): undefined reference to `libtorrent::torrent_info::~torrent_info()'
collect2: error: ld returned 1 exit status

还尝试使用编译:g++ -I /usr/include/ -L /usr/local/lib -lboost_system -lpthread -lboost_thread main.cpp结果相同。

更新 3:

我能够解决问题。我不得不使用编译: g++ -I /usr/include/ -L /usr/local/lib -lboost_system -lpthread -lboost_thread main.cpp并添加链接库 -ltorrent-rasterbar

最佳答案

听起来您已经编译了该库,但实际上并未将其安装在任何地方。默认情况下,#include 指令会在 /usr/include 中查找,但 libtorrent header 位于您构建库的目录中的某个位置。您需要将库的文件安装到系统目录中,或者为编译器提供指向 libtorrent 构建目录的 -I 选项。 (出于同样的原因,您在链接时可能还需要一个 -L 选项。)

关于c++ - 构建库 libtorrent debian 并将其链接到程序 c++,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38996963/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com