vs2005下的libtorrent平台搭建

打开Halite solution,在solution下新建一个console工程比如PatchP2P,然后在该工程下新建一个cpp文件比如PathcP2P.cpp,然后把这个文件拷贝进去(这个cpp来自libtorrent的doc中的example):
  1. #include <iostream>
  2. #include <fstream>
  3. #include <iterator>
  4. #include <iomanip>
  5. #include "libtorrent/entry.hpp"
  6. #include "libtorrent/bencode.hpp"
  7. #include "libtorrent/torrent_info.hpp"
  8. int main(int argc, char* argv[])
  9. {
  10.     using namespace libtorrent;
  11.     if (argc != 2)
  12.     {
  13.         std::cerr << "usage: dump_torrent torrent-file/n";
  14.         return 1;
  15.     }
  16.     try
  17.     {
  18.         std::ifstream in(argv[1], std::ios_base::binary);
  19.         in.unsetf(std::ios_base::skipws);
  20.         entry e = bdecode(std::istream_iterator<char>(in)
  21.             , std::istream_iterator<char>());
  22.         std::cout << "/n/n----- raw info -----/n/n";
  23.         e.print(std::cout);
  24.         torrent_info t(e);
  25.         // print info about torrent
  26.         std::cout << "/n/n----- torrent file info -----/n/n";
  27.         std::cout << "nodes:/n";
  28.         typedef std::vector<std::pair<std::string, int> > node_vec;
  29.         node_vec const& nodes = t.nodes();
  30.         for (node_vec::const_iterator i = nodes.begin(), end(nodes.end());
  31.             i != end; ++i)
  32.         {
  33.             std::cout << i->first << ":" << i->second << "/n";
  34.         }
  35.         std::cout << "trackers:/n";
  36.         for (std::vector<announce_entry>::const_iterator i
  37.             = t.trackers().begin(); i != t.trackers().end(); ++i)
  38.         {
  39.             std::cout << i->tier << ": " << i->url << "/n";
  40.         }
  41.         std::cout << "number of pieces: " << t.num_pieces() << "/n";
  42.         std::cout << "piece length: " << t.piece_length() << "/n";
  43.         std::cout << "info hash: " << t.info_hash() << "/n";
  44.         std::cout << "comment: " << t.comment() << "/n";
  45.         std::cout << "created by: " << t.creator() << "/n";
  46.         std::cout << "files:/n";
  47.         for (torrent_info::file_iterator i = t.begin_files();
  48.             i != t.end_files(); ++i)
  49.         {
  50.             std::cout << "  " << std::setw(11) << i->size
  51.                 << " " << i->path.string() << "/n";
  52.         }
  53.     }
  54.     catch (std::exception& e)
  55.     {
  56.         std::cout << e.what() << "/n";
  57.     }
  58.     getchar();
  59.     return 0;
  60. }

设置工程属性,把c/c++ -> 代码生成 -> 运行时库设为“多线程调试(/MTd)”,把c/c++ -> 预处理器 -> 预处理器定义设为

“WIN32_LEAN_AND_MEAN;_WIN32_WINNT=0x0500;__USE_W32_SOCKETS;WIN32;_WIN32;_WINDOWS;_DEBUG;TORRENT_USE_BOOST_DATE_TIME;TORRENT_USE_OPENSSL;_CRT_SECURE_NO_DEPRECATE;_SCL_SECURE_NO_

DEPRECATE;_CRT_SECURE_NO_WARNINGS;_SECURE_SCL=0”,然后将libtorrent,asio,boost1.34,openssl的include目录加入c/c++ -> 常规 -> 附加包含目录,可以这样添加:$(SolutionDir)

lib/libtorrent/include";"$(SolutionDir)lib/libtorrent/zlib";"$(SolutionDir)lib/Asio/include/";"$(SolutionDir)lib/Openssl/inc";E:/9c/boost134/boost_1_34_1。在链接器 -> 常规 -> 附

加库目录中加入boost1.34和libtorrent的lib文件所在的目录,比如E:/9c/boost134/boost_1_34_1/stage/lib;E:/9c/P2P/Halite/Halite.0_3_1.src/debug,在链接器 -> 输入 -> 附加依赖项中加入

libtorrent和openssl的lib,比如libtorrent.lib "$(SolutionDir)lib/openssl/bin/debug/link-static/runtime-link-static/threading-multi/libeay32.lib" "$(SolutionDir)

lib/openssl/bin/debug/link-static/runtime-link-static/threading-multi/ssleay32.lib"。然后编译成PatchP2P.exe文件,在命令行下运行,参数为某个torrent文件,程序运行的结果是打印出该

torrent文件的信息。
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值