vs2008 编译libtorrent

网上可参考的文章已经有很多很详细了,主要参考:

http://hi.baidu.com/chinacharis/blog/item/f58bef76e02ede12b051b92a.html 编译openssl

http://www.boost.org/doc/libs/1_39_0/more/getting_started/windows.html 编译boost boost.org 1.39.0版本的英文参考

http://hi.baidu.com/chinacharis/blog/item/7debed65c72917f9f7365413.html 编译libtorrent

 

但是有些需要自己注意的地方:

编译boost 的时候:

  •  出现error,修改了ms目录下的ntdll.mak文件,把-w3修改为-w0

编译libtorrent的时候:

 

  • 报错1:GeoIP.c :没找到"libtorrent/GeoIP.cpp" ,增加预处理器定义:WITH_SHIPPED_GEOIP_H

 

 

  •  报错2: \boost_1_39_0\boost\asio\ssl\detail\openssl_context_service.hpp(74) : error C2440: “=”: 无法从“const SSL_METHOD *”转换为“SSL_METHOD *” 所以我将openssl_context_service.hpp中的那个变量声明前加了const修饰符( const ::SSL_METHOD* ssl_method = 0;),编译就通过了

编译通过生成exe成功。

运行时报错:找不到:libeay32.dll ssleay32.dll,于是 添加 libeay32.dll ssleay32.dll ,openssl.exe 放到exe同样的目录下。


 

 使用release 版本,之前用debug 弄了几天都是运行时抛出异常,具体如下:

  • 有时文件作为输入参数时,只是输出文件名,然后退出。
  • 文件夹作为输入参数时,抛出异常,输出come to error,然后退出。
  • debug 版本在make_torrent的example 的 addfile 出错,最终跳到boost 的filesystem的源码里面(有时是is_directory函数)

 

路径含有中文是会出错的, http://www.cppblog.com/hblhs/archive/2008/10/21/64597.html给出了解决方案(但经测试,不完全正确,需要做以下更改)

ExpandedBlockStart.gif View Code
std::wstring safe_convert(std:: string   const &  s)
 {
  
/* try
  {
   return libtorrent::utf8_wchar(s);
  }
  catch (std::exception)
  {
   std::wstring ret;
   const char* end = &s[0] + s.size();
   for (const char* i = &s[0]; i < end;)
   {
    wchar_t c = '.';
    int result = std::mbtowc(&c, i, end - i);
    if (result > 0) i += result;
    else ++i;
    ret += c;
   }
   return ret;
  }
*/// wchar_t wc;
  wchar_t  * wcs  =   new  wchar_t[s.size()];
  
  setlocale(LC_CTYPE, 
" chs " );   // 原setlocale(LC_CTYPE, ""); 
 
  mbstowcs(wcs, s.c_str(), s.size() 
+   1 );  // 参考的文章缺少这个+1
 
  std::wstring newword(wcs);

  delete[] wcs;
  
return  newword;
 }

 

参考 http://www.cppblog.com/kenwell/archive/2008/05/21/50661.html 经较多测试,使用以下较好:

ExpandedBlockStart.gif View Code
std::wstring s2ws( const  std:: string &  s)
{
    setlocale(LC_ALL, 
" chs " ); 
    
const   char *  _Source  =  s.c_str();
    size_t _Dsize 
=  s.size()  +   1 ;
    wchar_t 
* _Dest  =   new  wchar_t[_Dsize];
    wmemset(_Dest, 
0 , _Dsize);
    mbstowcs(_Dest,_Source,_Dsize);
    std::wstring result 
=  _Dest;
    delete []_Dest;
    setlocale(LC_ALL, 
" C " );
    
return  result;
}

将以上的实现替换掉storage.cpp 的safe_convert

其评论也有个更 简洁的,但未测试:

ExpandedBlockStart.gif 更简洁的版本
string  a  =   " xxxx " ;
wstring b(a.begin(), a.end());

 

其他如参考所言网页

 

采用的环境

boost_1_39_0
libtorrent
- rasterbar - 0.14 . 4
Unicode编码环境
vs 
2008
win 
2003  server sp2
我使用的是make_torrent  的实例代码

 

然后一切就绪。

测试运行:

T_libTorrent.exe c:\1.torrent http:192.168.2.41:6969/announce d:\testtorrent

生成成功,bitcomet成功解析,bnbt成功接收,2台机器成功互传数据。

 

转载于:https://www.cnblogs.com/no7dw/archive/2011/09/15/2177910.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值