Visual Studio libtorrent

From LimeWire
Jump to: navigation, search

Contents

How to Build libtorrent in Visual Studio

for Fun and Profit

http://www.rasterbar.com/products/libtorrent/building.html do section building with BBv2
http://www.rasterbar.com/products/libtorrent/vs2005_build_notes.html out of date
http://code.rasterbar.com/libtorrent/wiki/Building down
http://github.com/zootella/ltorrent code and project

Windows

Windows XP SP3 and Windows Update
Visual Studio 2008 and SP1
Windows SDK Version 7, published July 24 2009

----snapshot vs2008----

Cygwin including perl

Code

Place Code

openssl.org download a file like openssl-0.9.8l.tar.gz
Unzip to path like:
C:\openssl\Makefile.bak

boost.org download a file like boost_1_42_0.zip
Unzip to path like:
C:\boost_1_42_0\boost-build.jam

https://libtorrent.svn.sourceforge.net/svnroot/libtorrent/tags find the highest numbered tag

svn co https://libtorrent.svn.sourceforge.net/svnroot/libtorrent/tags/libtorrent-0_14_8 libtorrent

Move to path like
C:\libtorrent\project-root.jam

----snapshot a----

Make bjam

Visual Studio 2008 Command Prompt

cd C:\boost_1_42_0\tools\jam\src
build.bat

Creates the file:
C:\boost_1_42_0\tools\jam\src\bin.ntx86\bjam.exe
Copy bjam.exe to the build folder, alongside the v2 folder:
C:\boost_1_42_0\tools\build\bjam.exe

Open in Notepad:
C:\boost_1_42_0\tools\build\v2\user-config.jam
Uncomment the line using msvc ;

Build libraries

Visual Studio 2008 Command Prompt

set PATH=%PATH%;C:\boost_1_42_0\tools\build;C:\cygwin\bin

Build OpenSSL

cd C:\openssl
perl Configure --openssldir=C:/openssl VC-WIN32
ms\do_masm
nmake -f ms\nt.mak > result1.txt
nmake -f ms\nt.mak test > result2.txt
nmake -f ms\nt.mak install > result3.txt

Build boost

cd C:\boost_1_42_0
bjam --toolset=msvc link=static runtime-link=static variant=debug > result4.txt
bjam --toolset=msvc link=static runtime-link=static variant=release > result5.txt

Build libtorrent

cd C:\libtorrent
set BOOST_ROOT=C:\boost_1_42_0
set INCLUDE=%INCLUDE%;C:\openssl\include
set LIB=%LIB%;C:\openssl\out32
bjam --toolset=msvc boost=source link=static runtime-link=static variant=debug character-set=unicode --without-python > result6.txt
bjam --toolset=msvc boost=source link=static runtime-link=static variant=release character-set=unicode --without-python > result7.txt

Move libtorrent.lib

Move from:
C:\libtorrent\bin\msvc-9.0\debug\boost-source\link-static\threading-multi\libtorrent.lib
C:\libtorrent\bin\msvc-9.0\release\boost-source\link-static\threading-multi\libtorrent.lib
Rename to:
C:\libtorrent\lib\libtorrent-debug.lib
C:\libtorrent\lib\libtorrent-release.lib

----snapshot b----

Visual Studio

New Project

Visual Studio 2008
File, New, Project
Project types: Visual C++, Win32, Win32 Project
Name: ltorrent
Location: C:\Documents
Uncheck Create directory for solution
OK
Application Settings, check Empty Project
Finish

Project, Add Existing Item
select all the .h files, Add
Do it again for the .cpp files

Include and Lib

Tools, Options, Projects and Solutions, VC++ Directories

Include files

  • C:\openssl\include
  • C:\boost_1_42_0
  • C:\libtorrent\include
  • C:\libtorrent\zlib

Library files

  • C:\openssl\lib
  • C:\boost_1_42_0\stage\lib
  • C:\libtorrent\lib

Properties

Project, Properties, Configuration Properties

  • General, Use of ATL: Not Using ATL
  • General, Character Set: Use Unicode Character Set
  • C/C++, Code Generation, Runtime Library: change /MDd to /MTd and /MD to /MT to get rid of dll
  • C/C++, Precompiled Headers, Create/Use Precompiled Header: Not Using Precompiled Headers
  • Linker, Manifest File, Generate Manifest: No
  • Manifest Tool, Input and Output, Embed Manifest: No

At the end, check all with Configuration Debug and Release

Where other things live

  • C/C++, Preprocessor, Preprocessor Definitions (like WIN32_LEAN_AND_MEAN)
  • C/C++, Command Line
  • Linker, Command Line

Linker, Input, Additional Dependencies, Debug

  • advapi32.lib
  • comctl32.lib
  • ssleay32.lib
  • libeay32.lib
  • libboost_date_time-vc90-mt-sgd.lib
  • libboost_filesystem-vc90-mt-sgd.lib
  • libboost_system-vc90-mt-sgd.lib
  • libboost_thread-vc90-mt-sgd.lib
  • libtorrent-debug.lib

Release

  • advapi32.lib
  • comctl32.lib
  • ssleay32.lib
  • libeay32.lib
  • libboost_date_time-vc90-mt-s.lib
  • libboost_filesystem-vc90-mt-s.lib
  • libboost_system-vc90-mt-s.lib
  • libboost_thread-vc90-mt-s.lib
  • libtorrent-release.lib

Maybe try later

  • Configuration Release, General, Whole Program Optimization: Yes
  • Configuration Release, C/C++, Optimization, Optimization: Minimize Size 01

Optional steps to start the resources from scratch

  • menu File, Add New Item
  • choose Resource File (.rc), enter name, Open

Code

Add Code

Drop libtorrentwrapper.cpp next to Hello.cpp
C:\Documents\Visual Studio 2008\Projects\Hello\libtorrentwrapper.cpp
Project, Add Existing Item, libtorrentwrapper.cpp, Add

Comment out class blacklist_ip_filter_callback and fix errors

----snapshot c----

Manifest

just for common controls, the runtime is already inside the exe



END
#endif    // APSTUDIO_INVOKED


/////////////////////////////////////////////////////////////////////////////
//
// RT_MANIFEST
//

1                       RT_MANIFEST             "ltorrent.exe.manifest"
#endif    // English (U.S.) resources
/////////////////////////////////////////////////////////////////////////////



#ifndef APSTUDIO_INVOKED
Personal tools