Skip to content

Instantly share code, notes, and snippets.

@viocost
Last active May 11, 2019 06:28
Show Gist options
  • Select an option

  • Save viocost/a350993745421afa3aabf2d35525e652 to your computer and use it in GitHub Desktop.

Select an option

Save viocost/a350993745421afa3aabf2d35525e652 to your computer and use it in GitHub Desktop.
[Libtorrent linux build] building libtorrent python bindings in Linux from source using Boost #libtorrent #linux #build

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

  1. Download boost
  2. Unpack to ~/boost for convenience
  3. Run ~/boost/boostsrap.sh.
  4. Copy ~/boost/b2 and ~/boost/bjam to /usr/bin
  5. 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
  1. Copy file user-config.jam from ~/boost/tools/build/example to ~/
  2. Open it and insert:
	using gcc ;
	using python : 3.7 : /usr/bin/python3 : /usr/include/python3.7m : /usr/lib ;
  1. cd into ~/boost and run:
	b2 --with-python stage
  1. This will build Boost.Python shared oject in ~/boost/stage/lib
  2. Copy everything from ~/boost/stage/lib to /usr/lib
  3. Get libtorrent source in ~/libtorrent for convenience
  4. 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

  1. Run
python3 setup.py --bjam build

to build libtorrent.

  1. 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment