7.2 KiB
Build libtorrent from source
Check libtorrent documentation for any updates to build procedures.
Ubuntu / Debian
- 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 libboost-chrono-dev libboost-random-dev libssl-dev
- Download libtorrent and extract:
tar xf libtorrent-rasterbar.tar.gz
cd libtorrent-rasterbar
- Configure:
./configure --enable-python-binding --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
anderror
can also be used. - Debug: To create a debug build add
--enable-debug=yes
. - ARM architecture (Raspberry Pi, etc): add
--with-boost-libdir=/usr/lib/arm-linux-gnueabihf
at the end to avoid boost library error.
- Build:
make -j$(nproc)
- CPU Cores: The
make
option-j$(nproc)
will utilize all available cpu cores. - Non-specific errors: e.g.
g++: internal compiler error: Killed (program cc1plus)
try using a [#TemporarySwapFileforRasperryPiorlowmemorysystems temporary swap file]
- 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
.
Running ldconfig
avoids an ImportError
for libtorrent-rasterbar.so
, a result of Python being unable to find the main library.
- Verify libtorrent and the python bindings are installed correctly:
python3 -c "import libtorrent; print (libtorrent.version)"
>> 1.0.6.0
Temporary Swap File for Rasperry Pi or low memory systems
Compiling libtorrent requires a lot of memory/swap during the make
process ~1-2GB.
If you get an internal error during the make phase on a computer with low memory and/or no swap partition (verify with free -m
) you can try the below procedure.
- Create a 1GB empty swap file, (use a drive location that has enough free space):
dd if=/dev/zero of=/.swapfile bs=1M count=1024
- Format swap file:
mkswap /.swapfile
- Activate swap file:
sudo swapon /.swapfile
- Verify swap file is recognized:
swapon -s
- Start/restart your libtorrent build.
- Disable swap file:
swapoff /.swapfile
- Delete swap file:
rm -f /.swapfile
Windows
-
Download and install/extract these packages:
- MS VC++ Compiler for Python
- OpenSSL requirement needs building from source.
- Python 2.7
- MSVC 2008 SP1 Redist Package (x86)
- .NET Framework 3.5
- Boost
- libtorrent
Note: Install or extract to a path without spaces e.g.
C:\
drive. -
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
. -
Boost Build Steps:
In the boost directory run the following:
bootstrap.bat
Due to a boost bug with
VC for Python
, need to editproject-config.jam
in boost folder to the following:using msvc : : : <setup>"%USERPROFILE%\\AppData\\Local\\Programs\\Common\\Microsoft\\Visual C++ for Python\\9.0\\vcvarsall.bat" ;
Then run:
b2 --with-system --with-date_time --with-python --with-chrono --with-random
-
Create a Boost
user-config.jam
file in the toplevel folder (e.g.C:\boost
) with the following to forcemsvc
version:using msvc : 9.0 : : <setup>"%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. -
libtorrent Build Steps:
a. Setup the Environmental Variables:
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 include=C:\OpenSSL-Win32\include linkflags=/LIBPATH:C:\OpenSSL-Win32\lib -j%NUMBER_OF_PROCESSORS% --hash
Note1: Modify the paths for OpenSSL if installed to a different location.
Note2: For libtorrent versions <=1.0.6 rename
libtorrent-link
tolink
.For libtorrent versions >=1.1:
b2 libtorrent-link=static boost-link=static release optimization=space encryption=on crypto=openssl include=C:\OpenSSL-Win32\include linkflags=/LIBPATH:C:\OpenSSL-Win32\lib -j%NUMBER_OF_PROCESSORS% --hash
Upon a successful build the library file named
libtorrent.pyd
is created in the currentbindings/python
directory.
Debugging libtorrent on Windows
-
Download and install just the
debug tools
: -
Build libtorrent with debug enabled by changing
release
todebug
in theb2
build line. -
Open
windbg
(C:\Program Files\Debugging Tools for Windows (x86)\windbg.exe):File|Open Executable
and tickDebug child processes
- Hit
F5
orGo
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;srvc:\Symbolshttp://msdl.microsoft.com/download/symbols
Debug References:
* [Mozilla WinDbg stacktrace](https://developer.mozilla.org/en/docs/How_to_get_a_stacktrace_with_WinDbg)
* [Windbg for Beginners](http://gui-at.blogspot.co.uk/2010/01/windbg-for-beginners.html)
## Further Resources
* [libtorrent](http://libtorrent.org/building.html)
* [Leechcraft](http://leechcraft.org/development-building-from-source-win32#Building_libtorrent)
* [QBittorrent](https://github.com/qbittorrent/qBittorrent/wiki/Compiling-with-MSVC-2008%28static-linkage%29)