pythonbuildlibtorrent

libtorrent build fails with python3.12


I'm trying to install libtorrent with python3.12 on macOS Monterey. Here's how I install dependencies according to the docs:

brew install boost-build boost openssl@1.1

Then I do:

git clone --recurse-submodules https://github.com/arvidn/libtorrent.git
cd libtorrent
export LDFLAGS="-L/usr/local/opt/openssl@1.1/lib"                  
export CPPFLAGS="-I/usr/local/opt/openssl@1.1/include"
python setup.py bdist_wheel  # or python setup.py build

whichever command is used, it runs for a few minutes then gives the error below (truncated for character limit):

% python setup.py bdist_wheel
running bdist_wheel
b2 version: (1, 5, 2, 1)
running build
running build_ext
project-config.jam contents:
import feature ;
feature.feature libtorrent-python : on ;
using python : 3.12 : "/usr/local/opt/python@3.12/bin/python3.12" : "/usr/local/opt/python@3.12/Frameworks/Python.framework/Versions/3.12/include/python3.12" : __BLOCK_AUTODETECTION__ : <libtorrent-python>on : ".cpython-312-darwin" ;

b2 cxxstd=14 toolset=darwin deprecated-functions=on boost-link=static libtorrent-link=static crypto=openssl variant=release address-model=64 architecture=x86 python=3.12 libtorrent-python=on python-install-path=/Users/user/Desktop/libtorrent 2/bindings/python/build/lib.macosx-12.0-x86_64-cpython-312 install_module --project-config=/var/folders/37/0vwkmsy91wg8fvk79zp4wgy40000gn/T/tmp8v7o8ahk
CXXFLAGS =
LDFLAGS =
OS = MACOSX
CXXFLAGS =
LDFLAGS =
warning: non-free usage requirements <visibility>hidden ignored
warning: in main-target torrent at ../../Jamfile:978
...patience...
...patience...
...patience...
...patience...
...patience...
...patience...
...found 6723 targets...
...updating 227 targets...
darwin.compile.c++ bin/darwin-14.0.0/release/address-model-64/architecture-x86/cxxstd-14-iso/python-3.12/src/module.o
darwin.compile.c++ ../../deps/try_signal/bin/darwin-14.0.0/release/address-model-64/architecture-x86/cxxstd-14-iso/link-static/threading-multi/visibility-hidden/signal_error_code.o
darwin.compile.c++ ../../deps/try_signal/bin/darwin-14.0.0/release/address-model-64/architecture-x86/cxxstd-14-iso/link-static/threading-multi/visibility-hidden/try_signal.o
darwin.archive ../../deps/try_signal/bin/darwin-14.0.0/release/address-model-64/architecture-x86/cxxstd-14-iso/link-static/threading-multi/visibility-hidden/libtry_signal.a
darwin.compile.c++ ../../bin/darwin-14.0.0/release/address-model-64/architecture-x86/cxxstd-14-iso/link-static/threading-multi/visibility-hidden/src/announce_entry.o
darwin.compile.c++ ../../bin/darwin-14.0.0/release/address-model-64/architecture-x86/cxxstd-14-iso/link-static/threading-multi/visibility-hidden/src/assert.o
darwin.compile.c++ bin/darwin-14.0.0/release/address-model-64/architecture-x86/cxxstd-14-iso/python-3.12/src/sha1_hash.o
darwin.compile.c++ bin/darwin-14.0.0/release/address-model-64/architecture-x86/cxxstd-14-iso/python-3.12/src/error_code.o
darwin.compile.c++ bin/darwin-14.0.0/release/address-model-64/architecture-x86/cxxstd-14-iso/python-3.12/src/alert.o
darwin.link.dll bin/darwin-14.0.0/release/address-model-64/architecture-x86/cxxstd-14-iso/python-3.12/libtorrent.cpython-312-darwin.so
ld: warning: directory not found for option '-L/opt/homebrew/lib'
ld: warning: directory not found for option '-L/opt/homebrew/opt/openssl/lib'
ld: warning: option -no_dead_strip_inits_and_terms is obsolete and being ignored
ld: library not found for -lboost_python312
clang: error: linker command failed with exit code 1 (use -v to see invocation)

    "g++" -dynamiclib -Wl,-single_module -install_name "libtorrent.cpython-312-darwin.so" -L"/opt/homebrew/lib" -L"/opt/homebrew/opt/openssl/lib" -L"/usr/local/opt/boost/lib" -L"/usr/local/opt/openssl/lib" -o "bin/darwin-14.0.0/release/address-model-64/architecture-x86/cxxstd-14-iso/python-3.12/libtorrent.cpython-312-darwin.so" "bin/darwin-14.0.0/release/address-model-64/architecture-x86/cxxstd-14-iso/python-3.12/src/module.o" "bin/darwin-14.0.0/release/address-model-64/architecture-x86/cxxstd-14-iso/python-3.12/src/sha1_hash.o" "bin/darwin-14.0.0/release/address-model-64/architecture-x86/cxxstd-14-iso/python-3.12/src/sha256_hash.o" "bin/darwin-14.0.0/release/address-model-64/architecture-x86/cxxstd-14-iso/python-3.12/src/info_hash.o" "bin/darwin-14.0.0/release/address-model-64/architecture-x86/cxxstd-14-iso/python-3.12/src/converters.o" "bin/darwin-14.0.0/release/address-model-64/architecture-x86/cxxstd-14-iso/python-3.12/src/create_torrent.o" "bin/darwin-14.0.0/release/address-model-64/architecture-x86/cxxstd-14-iso/python-3.12/src/fingerprint.o" "bin/darwin-14.0.0/release/address-model-64/architecture-x86/cxxstd-14-iso/python-3.12/src/utility.o" "bin/darwin-14.0.0/release/address-model-64/architecture-x86/cxxstd-14-iso/python-3.12/src/session.o" "bin/darwin-14.0.0/release/address-model-64/architecture-x86/cxxstd-14-iso/python-3.12/src/entry.o" "bin/darwin-14.0.0/release/address-model-64/architecture-x86/cxxstd-14-iso/python-3.12/src/torrent_info.o" "bin/darwin-14.0.0/release/address-model-64/architecture-x86/cxxstd-14-iso/python-3.12/src/string.o" "bin/darwin-14.0.0/release/address-model-64/architecture-x86/cxxstd-14-iso/python-3.12/src/torrent_handle.o" "bin/darwin-14.0.0/release/address-model-64/architecture-x86/cxxstd-14-iso/python-3.12/src/torrent_status.o" "bin/darwin-14.0.0/release/address-model-64/architecture-x86/cxxstd-14-iso/python-3.12/src/session_settings.o" "bin/darwin-14.0.0/release/address-model-64/architecture-x86/cxxstd-14-iso/python-3.12/src/version.o" "bin/darwin-14.0.0/release/address-model-64/architecture-x86/cxxstd-14-iso/python-3.12/src/alert.o" "bin/darwin-14.0.0/release/address-model-64/architecture-x86/cxxstd-14-iso/python-3.12/src/datetime.o" "bin/darwin-14.0.0/release/address-model-64/architecture-x86/cxxstd-14-iso/python-3.12/src/peer_info.o" "bin/darwin-14.0.0/release/address-model-64/architecture-x86/cxxstd-14-iso/python-3.12/src/ip_filter.o" "bin/darwin-14.0.0/release/address-model-64/architecture-x86/cxxstd-14-iso/python-3.12/src/magnet_uri.o" "bin/darwin-14.0.0/release/address-model-64/architecture-x86/cxxstd-14-iso/python-3.12/src/error_code.o" "bin/darwin-14.0.0/release/address-model-64/architecture-x86/cxxstd-14-iso/python-3.12/src/load_torrent.o" "../../bin/darwin-14.0.0/release/address-model-64/architecture-x86/cxxstd-14-iso/link-static/threading-multi/visibility-hidden/libtorrent-rasterbar.a" "../../deps/try_signal/bin/darwin-14.0.0/release/address-model-64/architecture-x86/cxxstd-14-iso/link-static/threading-multi/visibility-hidden/libtry_signal.a"  -lssl -lcrypto -lboost_python312 -lboost_system-mt -lssl -lcrypto  -framework CoreFoundation -framework SystemConfiguration -headerpad_max_install_names -fPIC -m64 -std=c++14 -Wl,-dead_strip -no_dead_strip_inits_and_terms -undefined dynamic_lookup

...failed darwin.link.dll bin/darwin-14.0.0/release/address-model-64/architecture-x86/cxxstd-14-iso/python-3.12/libtorrent.cpython-312-darwin.so...
...skipped <p/Users/user/Desktop/libtorrent 2/bindings/python/build/lib.macosx-12.0-x86_64-cpython-312>libtorrent.cpython-312-darwin.so for lack of <pbin/darwin-14.0.0/release/address-model-64/architecture-x86/cxxstd-14-iso/python-3.12>libtorrent.cpython-312-darwin.so...

...updated 225 targets...

...skipped 1 target...
   <p/Users/user/Desktop/libtorrent 2/bindings/python/build/lib.macosx-12.0-x86_64-cpython-312>libtorrent.cpython-312-darwin.so

...failed updating 1 target...
   darwin.link.dll bin/darwin-14.0.0/release/address-model-64/architecture-x86/cxxstd-14-iso/python-3.12/libtorrent.cpython-312-darwin.so
Traceback (most recent call last):
  File "/Users/user/Desktop/libtorrent 2/setup.py", line 6, in <module>
    runpy.run_path("setup.py")
  File "<frozen runpy>", line 286, in run_path
  File "<frozen runpy>", line 98, in _run_module_code
  File "<frozen runpy>", line 88, in _run_code
  File "setup.py", line 505, in <module>
    setuptools.setup(
  File "/usr/local/lib/python3.12/site-packages/setuptools/__init__.py", line 117, in setup
    return distutils.core.setup(**attrs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/setuptools/_distutils/core.py", line 184, in setup
    return run_commands(dist)
           ^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/setuptools/_distutils/core.py", line 200, in run_commands
    dist.run_commands()
  File "/usr/local/lib/python3.12/site-packages/setuptools/_distutils/dist.py", line 954, in run_commands
    self.run_command(cmd)
  File "/usr/local/lib/python3.12/site-packages/setuptools/dist.py", line 950, in run_command
    super().run_command(command)
  File "/usr/local/lib/python3.12/site-packages/setuptools/_distutils/dist.py", line 973, in run_command
    cmd_obj.run()
  File "/usr/local/lib/python3.12/site-packages/setuptools/command/bdist_wheel.py", line 384, in run
    self.run_command("build")
  File "/usr/local/lib/python3.12/site-packages/setuptools/_distutils/cmd.py", line 316, in run_command
    self.distribution.run_command(command)
  File "/usr/local/lib/python3.12/site-packages/setuptools/dist.py", line 950, in run_command
    super().run_command(command)
  File "/usr/local/lib/python3.12/site-packages/setuptools/_distutils/dist.py", line 973, in run_command
    cmd_obj.run()
  File "/usr/local/lib/python3.12/site-packages/setuptools/_distutils/command/build.py", line 135, in run
    self.run_command(cmd_name)
  File "/usr/local/lib/python3.12/site-packages/setuptools/_distutils/cmd.py", line 316, in run_command
    self.distribution.run_command(command)
  File "/usr/local/lib/python3.12/site-packages/setuptools/dist.py", line 950, in run_command
    super().run_command(command)
  File "/usr/local/lib/python3.12/site-packages/setuptools/_distutils/dist.py", line 973, in run_command
    cmd_obj.run()
  File "setup.py", line 348, in run
    self._build_extension_with_b2()
  File "setup.py", line 355, in _build_extension_with_b2
    subprocess.run(command, cwd=PYTHON_BINDING_DIR, check=True)
  File "/usr/local/Cellar/python@3.12/3.12.5/Frameworks/Python.framework/Versions/3.12/lib/python3.12/subprocess.py", line 571, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['b2', 'cxxstd=14', 'toolset=darwin', 'deprecated-functions=on', 'boost-link=static', 'libtorrent-link=static', 'crypto=openssl', 'variant=release', 'address-model=64', 'architecture=x86', 'python=3.12', 'libtorrent-python=on', 'python-install-path=/Users/user/Desktop/libtorrent 2/bindings/python/build/lib.macosx-12.0-x86_64-cpython-312', 'install_module', '--project-config=/var/folders/37/0vwkmsy91wg8fvk79zp4wgy40000gn/T/tmp8v7o8ahk']' returned non-zero exit status 1.

..................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................


Solution

  • This message suggests that boost python is missing:

    ld: library not found for -lboost_python312
    

    You also need to install boost-python:

    brew install boost-python3
    

    Libtorrent's build script will assume the name of the library be boost_python<major><minor> That's "312" in your case.