wiseman / py-webrtcvad

Python interface to the WebRTC Voice Activity Detector
Other
2.02k stars 405 forks source link

can't install on macOs Monterey 12.1 (21C52) #79

Open sathio opened 2 years ago

sathio commented 2 years ago

I get this error

gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch x86_64 -g -I/usr/local/opt/zlib/include -I/usr/local/opt/bzip2/include -DWEBRTC_POSIX -Icbits -I/Users/sat/localhost/webrtcvad/venv/include -I/Library/Frameworks/Python.framework/Versions/3.7/include/python3.7m -c cbits/pywebrtcvad.c -o build/temp.macosx-10.9-x86_64-3.7/cbits/pywebrtcvad.o -std=c++11

error: invalid argument '-std=c++11' not allowed with 'C'

gcc -v
Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/4.2.1
Apple clang version 13.0.0 (clang-1300.0.29.30)
Target: x86_64-apple-darwin21.2.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin``` 
Invisibility commented 1 year ago

The reason is that clang doesn't allow -std=c++11 for C source file but -std=c++11 is needed for one C++ file in the extension.

I figured out one hack.

  1. Comment out this line in setup.py: extra_compile_args.extend(['-std=libc++'])
  2. Create the following shell script, chmod 755 the shell script and name it the same as your compiler (e.g. clang)
#!/bin/sh
echo wrapper called
if [[ "$@" == *"checks.cc"* ]]; then
   echo "c++ detected"
   /usr/bin/clang "$@" -std=c++11
else
   /usr/bin/clang "$@"
fi
  1. change the $PATH (using export PATH=<path to shell script>:$PATH) so the shell script will be invoked first
  2. run the install command
arkadijs commented 3 months ago

Instead of the wrapper script, another option is to install Clang 16 or later which defaults to C++17 standard. May also use CC=/path/to/clang.