构建库libtorrent debian并将其链接到程序c ++ [英] Build library libtorrent debian and link it to program c++

查看:52
本文介绍了构建库libtorrent debian并将其链接到程序c ++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I always have problems when building libraries and linking them, so I hope someone can give me a hand.

我从此处下载了libtorrent,并且像他们解释

I downloaded libtorrent from here and I've built it like they explain here in the building with autotools section (skipping step 1). The building process was successfull I think, but when I did make check the output was:

============================================================================
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:没有这样的文件或目录.

I did a little program where I added #include <libtorrent/session.hpp> and when I compile with g++ file.cpp -o file it says libtorrent/session.hpp: No such file or directory.

我应该在g ++中为其他项目添加一些标志,例如 -lpthread 并考虑吗?

Should I add some flags to g++ such as -lpthread for other projects and thinks like that?

谢谢

更新:在不使用 sudo apt-get安装libtorrent-rasterbar-dev 进行编译并编译我的main.cpp文件时,出现此错误:

UPDATE: When installing without building using sudo apt-get install libtorrent-rasterbar-dev and compiling my main.cpp file I get this error:

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 指令上方添加以下内容:

Modified the main.cpp file to add the the following above the libtorrent #include directives:

#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 ,结果相同.

Also tried compiling using: g++ -I /usr/include/ -L /usr/local/lib -lboost_system -lpthread -lboost_thread main.cpp with the same result.

更新3:

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

I was able to solve the problem. I had to compile using: g++ -I /usr/include/ -L /usr/local/lib -lboost_system -lpthread -lboost_thread main.cpp and add also the link library -ltorrent-rasterbar

推荐答案

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

Sounds like you've compiled the library but not actually installed it anywhere. An #include directive looks in /usr/include by default, but the libtorrent headers are somewhere in the directory where you built the library. You'll need to either install the library's files into the system directories, or give the compiler an -I option pointing to the libtorrent build directory. (You'll probably also need an -L option when linking, for the same reason.)

这篇关于构建库libtorrent debian并将其链接到程序c ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆