building issues on macOS
On macOS, /usr/local/include and /usr/local/lib are not automatically searched so pip install sox bindings fails.
I have fixed this by git cloning the soxbindings repo and making the following changes to the setup.py file:
% git diff setup.py
diff --git a/setup.py b/setup.py
index 3ee9d8c..8b2c894 100644
--- a/setup.py
+++ b/setup.py
@@ -27,6 +27,10 @@ ext_modules = [
include_dirs=[
# Path to pybind11 headers
get_pybind_include(),
+ "/usr/local/include",
+ ],
+ library_dirs=[
+ "/usr/local/lib",
],
language='c++'
),
The issue was that pip install soxbindings returns the following error:
clang -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX12.sdk -DVERSION_INFO=\"1.2.3\" -I/private/var/folders/kr/14n7z9ld603gn1x2vmy6ly6h0000gn/T/pip-install-290x3sk_/soxbindings_0dbb63f5456a4cef94426ff65d48ca6b/.eggs/pybind11-2.10.1-py3.10.egg/pybind11/include -I/Users/harri/Programming/quarto/venv/include -I/usr/local/opt/[email protected]/Frameworks/Python.framework/Versions/3.10/include/python3.10 -c soxbindings/ext/sox.cpp -o build/temp.macosx-12-x86_64-cpython-310/soxbindings/ext/sox.o -stdlib=libc++ -mmacosx-version-min=10.7 -lsox -std=c++17 -fvisibility=hidden
clang: warning: -lsox: 'linker' input unused [-Wunused-command-line-argument]
soxbindings/ext/sox.cpp:4:10: fatal error: 'sox.h' file not found
#include <sox.h>
^~~~~~~
1 error generated.
error: command '/usr/bin/clang' failed with exit code 1
After cloning the repo and making the above changes the following needs to be run (from the folder where the repo was cloned):
python setup.py install
For me, since I installed sox with homebrew, I had to change the folders to make it work:
ext_modules = [
Extension(
'soxbindings._soxbindings',
# Sort input source files to ensure bit-for-bit reproducible builds
# (https://github.com/pybind/python_example/pull/53)
sorted(['soxbindings/ext/sox.cpp']),
include_dirs=[
# Path to pybind11 headers
get_pybind_include(),
"/opt/homebrew/include/",
],
library_dirs=[
"/opt/homebrew/lib/",
],
language='c++'
),
]
After, I can run successfully (inside the cloned repo folder):
pip install -e .
Since this is a very configuration specific change, I don't know how to create PR to fix it 🤷
This might be interesting for readers of https://github.com/pytorch/audio/issues/53
I think you can generalize the solution to the following if you have installed sox using homebrew:
import subprocess
# ...
SOX_PREFIX = subprocess.check_output(['brew', '--prefix', 'sox'], encoding='utf8').strip()
#...
ext_modules = [
Extension(
'soxbindings._soxbindings',
# Sort input source files to ensure bit-for-bit reproducible builds
# (https://github.com/pybind/python_example/pull/53)
sorted(['soxbindings/ext/sox.cpp']),
include_dirs=[
# Path to pybind11 headers
get_pybind_include(),
f"{SOX_PREFIX}/include",
],
library_dirs=[
f"{SOX_PREFIX}/lib",
],
language='c++'
),
]