首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >构建库libtorrent debian并将其链接到程序c++

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

Stack Overflow用户
提问于 2016-08-17 12:41:47
回答 1查看 716关注 0票数 2

在建立和连接图书馆时,我总是遇到一些问题,所以我希望有人能帮我一把。

我从这里下载了libtorrent,构建它就像他们在building with autotools部分解释这里一样(跳过步骤1)。我认为构建过程是成功的,但是当我完成make check时,输出是:

代码语言:javascript
复制
============================================================================
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进行安装和编译文件的情况下,我得到了以下错误:

代码语言:javascript
复制
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指令:

代码语言:javascript
复制
#ifndef BOOST_ASIO_DYN_LINK
#define BOOST_ASIO_DYN_LINK
#endif

但我有个问题:

代码语言:javascript
复制
$ 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

EN

回答 1

Stack Overflow用户

发布于 2016-08-17 13:50:04

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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38996963

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档