Building libtorrent for Linux requires Boost.Python to be built separately, while on Mac and Windows Boost.Python is integratind in libtorrent.
Pre-requisites: 1. Installed python 3.7
- Download boost
- Unpack to ~/boost for convenience
- Run ~/boost/boostsrap.sh.
- Copy ~/boost/b2 and ~/boost/bjam to /usr/bin
- Add environment variables. Add following lines to ~/.bashrc replace username with actual username:
export BOOST_ROOT=/home/<username>/boost$BOOST_ROOT
export BOOST_BUILD_PATH=/home/<username>/boost/tools/build$BOOST_BUILD_PATH
- Copy file user-config.jam from ~/boost/tools/build/example to ~/
- Open it and insert:
using gcc ;
using python : 3.7 : /usr/bin/python3 : /usr/include/python3.7m : /usr/lib ;
- cd into ~/boost and run:
b2 --with-python stage
- This will build Boost.Python shared oject in ~/boost/stage/lib
- Copy everything from ~/boost/stage/lib to /usr/lib
- Get libtorrent source in ~/libtorrent for convenience
- Now there is 2 options: newly built Boost.Python can be installed in the system by copying everything from ~/boost/stage/lib to /usr/lib and libtorrent will always try to pull it from default lib path, or libtorrent can be built such that it would look in relative path. To change that, we need to open Jamfile in ~/libtorrent/bindings/python and edit <linkflags>\ . By default it is set to
-Wl,-Bsymbolic
which provides a means of binding symbol references to their global definitions within a shared object, so it would look for globally defined shared objects in default lib directory. If we change it to
-Wl,-rpath,.
then it will look for shared object within the same directory. Read more about -rpath for more customization
- Run
python3 setup.py --bjam build
to build libtorrent.
- Now you can use libtorrent.so in your project. Don't forget to include all the files from ~/boost/stage/lib to relative directory, otherwise libtorrent won't work as it will not be able to find Boost.Python