Nov. 15th 2014 - By Angel Leon. Tips are welcome.
- Install a binary
boost
distribution (it must contain the Boost.Python module) and make sure to setup theBOOST_ROOT
environment variable. - Download the libtorrent.tar.gz, and uncompress it.
- If you have the 1.0.2 version, you will have to go to
bindings\python
and remove thecompile_flags
andlink_flags
files which got packaged by mistake. - Move the
bindings\python\setup.py
script to the root of the libtorrent sources folder. - Apply the following patch:
+++ setup.py 2014-11-26 07:36:52.000000000 -0500
@@ -9,6 +9,8 @@
import multiprocessing
import subprocess
+os.chdir(os.path.join('bindings','python'))
+
def parse_cmd(cmdline, prefix, keep_prefix = False):
ret = []
for token in cmdline.split():
@@ -53,7 +55,8 @@
if '--bjam' in sys.argv or ldflags == None or extra_cmd == None:
- del sys.argv[sys.argv.index('--bjam')]
+ if '--bjam' in sys.argv:
+ del sys.argv[sys.argv.index('--bjam')]
if not '--help' in sys.argv \
and not '--help-commands' in sys.argv:
Now execute:
python setup.py bdist
That's it, if you go to your python terminal you can now import libtorrent
.
These fixes are being sent upstream and hopefully the process will then be as simple as pip install <url-to-libtorrent-tar-gz>
If you already had an old boost library that you want to get rid of and you built it manually, go to its source folder and type:
./b2 uninstall
-
Download the boost libraries source code. (I built this with 1.57.0)
-
Decompress and enter the boost sources directory
-
Set and export the
BOOST_ROOT
variable on your~/.bash_profile
export BOOST_ROOT=/Users/gubatron/src/boost_1_57_0
- Bootstrap Boost and let it know it's going to build the
Boost.Python
library using your OpenBazaar'senv/bin/python
executable path, in my computer I did it like this:
./bootstrap.sh --with-python=/Users/gubatron/workspace.frostwire/OpenBazaar/env/bin/python
- Build Boost
./b2
You should see this at the end:
The Boost C++ Libraries were successfully built!
The following directory should be added to compiler include paths:
/Users/gubatron/src/boost_1_57_0
The following directory should be added to linker library paths:
/Users/gubatron/src/boost_1_57_0/stage/lib
- export the
BOOST_LIB_PATH
convenience environment variable
export BOOST_LIB_PATH=$BOOST_ROOT/stage/lib
- update your
LDFLAGS
environment variable to include yourBOOST_LIB_PATH
LDFLAGS="$LDFLAGS -L$BOOST_LIB_PATH"
export LDFLAGS
- update your
CPPFLAGS
environment variable to include yourBOOST_ROOT
path
CPPFLAGS="$CPPFLAGS -I$BOOST_ROOT"
export CPPFLAGS
- Install Boost
(it will install by default on /usr/local/
, you can pass --prefix=
to specify a custom installation location, you can also specify a --build-dir=
location)
./b2 install
- Set and export the
BOOST_BUILD_PATH
andCXXFLAGS
environment variables on your~/.bash_profile
(make sure it's active before the next steps)
export BOOST_BUILD_PATH=$BOOST_ROOT/tools/build
export CXXFLAGS="-stdlib=libc++ -std=c++11 -O3 -I$BOOST_ROOT"
-
Download the libtorrent sources (or clone them from the original SVN repo, or a synced Git repo)
-
Extract the sources, and from the libtorrent source folder execute:
$BOOST_ROOT/bjam toolset=darwin boost=source boost-link=shared link=shared variant=release deprecated-functions=off dht=on
Other parameters to consider depending if you're building for development or releasing:
debug-symbols=on|off
i2p=on|off
logging=none|default|verbose|errors
asserts=auto|on|off|productions (auto sets them on if debug mode is on)
If you get a error: feature already defined:
error message executing $BOOST_ROOT/bjam
:
/Users/gubatron/src/boost_1_57_0/tools/build/src/build/feature.jam:139: in feature.feature from module feature
error: feature already defined:
error: in feature declaration:
error: feature "valgrind" : "on" : "optional" "propagated" "composite"
edit $BOOST_ROOT/libs/coroutine/build/Jamfile.v2
around line 14
,15
, and comment out:
#feature.feature valgrind : on : optional propagated composite ;
#feature.compose <valgrind>on : <define>BOOST_USE_VALGRIND ;
-
Make sure no older versions of
libtorrent.dylib
andlibtorrent.so
already exist as they will cause a lot of issues. Places to look are/usr/lib/
,/usr/local/lib
,/usr/local/lib/python2.7/site-packages/libtorrent.so
as python might try to load those instead of the one you're about to build. -
Check that your
LDFLAGS
,LD_LIBRARY_PATH
,DYLD_LIBRARY_PATH
don't have more than what you need. -
Inside your libtorrent sources folder go to
bindings/python
, replace thesetup.py
script with this one as the original (as of libtorrent 1.0.2 does not work on MacOSX) -
Since we'll be building these bindings for the OpenBazaar
OpenBazaar/env/bin/python
, we'll use that path to build the python-libtorrent bindings, otherwise you can just use the system'spython
. On my development environment it looked like this:
$/Users/gubatron/workspace.frostwire/OpenBazaar/env/bin/python setup.py bdist
- Test it
gubatrons-macbook-pro:OpenBazaar gubatron$ ./env/bin/python
Python 2.7.8 (default, Aug 24 2014, 21:26:19)
[GCC 4.2.1 Compatible Apple LLVM 5.1 (clang-503.0.40)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import libtorrent
>>>
This is what I'm getting on the build for setup.py