= Build libtorrent from source = [[PageOutline(2-4,,inline, unnumbered)]] Check libtorrent [http://www.libtorrent.org/building.html documentation] for any updates to build procedures. == Ubuntu / Debian == 1. Install dependencies for libtorrent build automatically using `build-dep`: {{{ sudo apt-get build-dep libtorrent-rasterbar sudo apt-get install checkinstall }}} '''OR''' if that fails manually install them: {{{ sudo apt-get install build-essential checkinstall libboost-system-dev libboost-python-dev libssl-dev libgeoip-dev }}} 2. Download [https://github.com/arvidn/libtorrent/releases libtorrent] and extract: {{{ tar xf libtorrent-rasterbar.tar.gz cd libtorrent-rasterbar }}} 2. Configure: {{{ ./configure --enable-python-binding --with-libgeoip --with-libiconv }}} - Missing `configure` script: (e.g. source code from git) create it with `./autotool.sh` (requires extra packages: `sudo apt-get install autoconf automake libtool`). - ''Logging:'' Add `--enable-logging=default` to get logs in the current working directory. `verbose` and `error` can also be used. - ''Debug:'' To create a debug build add `--enable-debug=yes`. 3. Build: {{{ make -j$(nproc) }}} - ''CPU Cores:'' The `make` option `-j$(nproc)` will utilize all available cpu cores. 4. Install library and python bindings: {{{ sudo checkinstall sudo ldconfig }}} ''Substituted `make install` for `checkinstall` as it creates a deb package for easier removal/re-install by `dpkg`.'' [[br]] ''Running `ldconfig` avoids an `ImportError` for `libtorrent-rasterbar.so`, a result of Python being unable to find the main library.'' 5. Verify libtorrent and the python bindings are installed correctly: {{{ python -c "import libtorrent; print libtorrent.version" >> 1.0.6.0 }}} == Windows == 1. Download and install/extract these packages: * [http://www.microsoft.com/en-us/download/details.aspx?id=44266 MS VC++ Compiler for Python] * [https://openssl.org/source/ OpenSSL] requirement needs [http://libtorrent.org/building.html#building-openssl-for-windows building from source]. * [http://www.python.org/ Python 2.7] * [http://www.microsoft.com/en-us/download/details.aspx?id=5582 MSVC 2008 SP1 Redist Package (x86)] * [https://www.microsoft.com/en-gb/download/details.aspx?id=21 .NET Framework 3.5] * [http://sourceforge.net/projects/boost/files/boost/ Boost] * [https://github.com/arvidn/libtorrent/releases libtorrent] ''Note: Install or extract to a path without spaces e.g. `C:\` drive.'' 2. Setup the Windows Command Prompt by executing `VC for Python` `vcvarsall.bat`, e.g.: {{{ "%USERPROFILE%\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\vcvarsall.bat" }}} ''Note: If using Visual Studio simple open a `Visual Studio 2008 Command Prompt`.'' 3. Boost Build Steps: Due to a [https://svn.boost.org/trac/boost/ticket/10817 boost bug] with `VC for Python`, need to edit `project-config.jam` in boost folder to the following: {{{ using msvc : : : "%USERPROFILE%\\AppData\\Local\\Programs\\Common\\Microsoft\\Visual C++ for Python\\9.0\\vcvarsall.bat" ; }}} In the boost directory run the following: {{{ bootstrap.bat b2 --with-system --with-date_time --with-python }}} 5. Create a Boost `user-config.jam` file in the toplevel folder (e.g. `C:\boost`) with the following to force `msvc` version: {{{ using msvc : 9.0 : : "%USERPROFILE%\\AppData\\Local\\Programs\\Common\\Microsoft\\Visual C++ for Python\\9.0\\vcvarsall.bat" ; }}} ''Note: For Visual Studio, simply `using msvc : 9.0 ;` is required. 6. libtorrent Build Steps: a. Setup the Environmental Variables: {{{ set INCLUDE=C:\OpenSSL-Win32\include;%INCLUDE% set LIB=C:\OpenSSL-Win32\lib;%LIB% set BOOST_BUILD_PATH=C:\boost set PATH=%BOOST_BUILD_PATH%;%PATH% }}} b. Navigate to libtorrent Python bindings folder: {{{ cd C:\libtorrent-rasterbar\bindings\python }}} c. Build libtorrent with Python bindings: {{{ b2 boost=source libtorrent-link=static geoip=static boost-link=static release optimization=space encryption=openssl }}} ''Note: For libtorrent versions <=1.0.6 replace `libtorrent-link` with `link`.'' {{{#!comment These are the old instructions but the setup.py in 0.16 does not build with openssl so not useful. {{{ C:\python27\python.exe setup.py build }}} If there is no `setup.py` (i.e. tarball from version control repo) use `setup.py.in` instead. You can create setup.py on Ubuntu: (although makes no difference to the windows section of the script) {{{ sudo apt-get install libtool libboost1.46-all-dev ./autotool.sh ./configure --enable-python-binding }}} There might be an error at the end about `shutil` unable to move the lib but can be ignored. Upon a successful build the resulting library file is named `libtorrent.pyd` and is located under this directory: `libtorrent-rasterbar\bindings\python\bin\msvc-9.0\release\boost-source\geoip-static\link-static\optimization-space` }}} Upon a successful build the library file named `libtorrent.pyd` is created in the current `bindings/python` directory. === Debugging libtorrent on Windows === * Download and install just the `debug tools`: * [http://msdn.microsoft.com/en-us/windows/hardware/hh852365.aspx Standalone Debugging Tools for Windows (WinDbg)] * Build libtorrent with debug enabled by changing `release` to `debug` in the `b2` build line. * Open `windbg` ''(C:\Program Files\Debugging Tools for Windows (x86)\windbg.exe)'': * `File|Open Executable` and tick `Debug child processes` * Hit `F5` or `Go` a few times to get the program running * After the crash execute: `!analyze -v -f`. * Symbols for libtorrent will be in the build output path: {{{ C:\libtorrent-rasterbar\bindings\python\bin\msvc-9.0\debug\boost-source\geoip-static\link-static\optimization-space\threading-multi }}} So the full symbols line should look something like this: {{{ srv*;C:\libtorrent-rasterbar\bindings\python\bin\msvc-9.0\debug\boost-source\geoip-static\link-static\optimization-space\threading-multi;C:\Python27\symbols;srv*c:\Symbols*http://msdl.microsoft.com/download/symbols }}} Debug References: * [https://developer.mozilla.org/en/docs/How_to_get_a_stacktrace_with_WinDbg Mozilla WinDbg stacktrace] * [http://gui-at.blogspot.co.uk/2010/01/windbg-for-beginners.html Windbg for Beginners] == Further Resources == * [http://libtorrent.org/building.html libtorrent] * [http://leechcraft.org/development-building-from-source-win32#Building_libtorrent Leechcraft] * [https://github.com/qbittorrent/qBittorrent/wiki/Compiling-with-MSVC-2008%28static-linkage%29 QBittorrent]