macos - 在 macos 上从 pybind11 文档构建 python_example 时出错

标签 macos build compiler-errors pybind11

遵循 pybind11 文档中的说明以获取位于 https://github.com/pybind/python_example 的示例构建的说明时出现编译器错误。

说明是 (1) 克隆 repo,和 (2) pip3 install ./python_example。

我在 OS X (Mojave) 上使用 python 3.7.3 和

c++ --version
Apple LLVM version 10.0.1 (clang-1001.0.46.4)
Target: x86_64-apple-darwin18.7.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

我对 python 包和 pybind11 很陌生,所以我有点迷茫,希望能得到新手指导。看起来错误与 C++ 运算符 new 和 delete 的实现有关。
如果是这样,我相信我不是第一个遇到这个问题的人,并且会很感激一个解决方案的指针。

我按照 github repo 中给出的步骤进行操作:
Cloning into 'python_example'...
remote: Enumerating objects: 13, done.
remote: Counting objects: 100% (13/13), done.
remote: Compressing objects: 100% (9/9), done.
remote: Total 132 (delta 4), reused 11 (delta 4), pack-reused 119
Receiving objects: 100% (132/132), 31.03 KiB | 373.00 KiB/s, done.
Resolving deltas: 100% (62/62), done.
$ pip3 install ./python_example/

这是完整的输出。存储库中的某些内容是否配置错误(我没有进行配置)?这是python版本的东西吗?缺少编译器标志?如果我使用此设置作为模板分发代码,我需要做些什么来增加可移植性吗?我有点担心“hello world”示例让我处于堆栈溢出状态!提前感谢您的帮助。
Processing ./python_example
Requirement already satisfied: pybind11>=2.3 in /usr/local/lib/python3.7/site-packages (from python-example==0.0.1) (2.3.0)
Building wheels for collected packages: python-example
  Building wheel for python-example (setup.py) ... error
  Complete output from command /usr/local/opt/python/bin/python3.7 -u -c "import setuptools, tokenize;__file__='/private/var/folders/7l/5r4qgkms4vb3xm6ktxdvh1l80000gn/T/pip-req-build-9f8udd0w/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" bdist_wheel -d /private/var/folders/7l/5r4qgkms4vb3xm6ktxdvh1l80000gn/T/pip-wheel-fk0w8_oq --python-tag cp37:
  running bdist_wheel
  running build
  running build_ext
  creating var
  creating var/folders
  creating var/folders/7l
  creating var/folders/7l/5r4qgkms4vb3xm6ktxdvh1l80000gn
  creating var/folders/7l/5r4qgkms4vb3xm6ktxdvh1l80000gn/T
  clang -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/System/Library/Frameworks/Tk.framework/Versions/8.5/Headers -I/usr/local/include -I/usr/local/opt/openssl/include -I/usr/local/opt/sqlite/include -I/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/include/python3.7m -c /var/folders/7l/5r4qgkms4vb3xm6ktxdvh1l80000gn/T/tmpag19sot6.cpp -o var/folders/7l/5r4qgkms4vb3xm6ktxdvh1l80000gn/T/tmpag19sot6.o -std=c++17
  clang -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/System/Library/Frameworks/Tk.framework/Versions/8.5/Headers -I/usr/local/include -I/usr/local/opt/openssl/include -I/usr/local/opt/sqlite/include -I/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/include/python3.7m -c /var/folders/7l/5r4qgkms4vb3xm6ktxdvh1l80000gn/T/tmpf327436e.cpp -o var/folders/7l/5r4qgkms4vb3xm6ktxdvh1l80000gn/T/tmpf327436e.o -fvisibility=hidden
  building 'python_example' extension
  creating build
  creating build/temp.macosx-10.14-x86_64-3.7
  creating build/temp.macosx-10.14-x86_64-3.7/src
  clang -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/System/Library/Frameworks/Tk.framework/Versions/8.5/Headers -I/usr/local/include/python3.7m -I/Users/stevescott/Library/Python/3.7/include/python3.7m -I/usr/local/include -I/usr/local/opt/openssl/include -I/usr/local/opt/sqlite/include -I/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/include/python3.7m -c src/main.cpp -o build/temp.macosx-10.14-x86_64-3.7/src/main.o -stdlib=libc++ -mmacosx-version-min=10.7 -DVERSION_INFO="0.0.1" -std=c++17 -fvisibility=hidden
  In file included from src/main.cpp:1:
  In file included from /usr/local/include/python3.7m/pybind11/pybind11.h:49:
  In file included from /usr/local/include/python3.7m/pybind11/attr.h:13:
  /usr/local/include/python3.7m/pybind11/cast.h:579:34: error: aligned allocation function of type 'void *(unsigned long, enum std::align_val_t)' is only available on macOS 10.14 or newer
                          vptr = ::operator new(type->type_size,
                                   ^
  /usr/local/include/python3.7m/pybind11/cast.h:579:34: note: if you supply your own aligned allocation functions, use -faligned-allocation to silence this diagnostic
  In file included from src/main.cpp:1:
  /usr/local/include/python3.7m/pybind11/pybind11.h:1009:9: error: no matching function for call to 'operator delete'
          ::operator delete(p, s, std::align_val_t(a));
          ^~~~~~~~~~~~~~~~~
  note: candidate function not viable: requires 2 arguments, but 3 were provided
  /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/new:188:36: note: candidate function not viable: requires 2 arguments, but 3 were provided
  _LIBCPP_OVERRIDABLE_FUNC_VIS void  operator delete(void* __p, const std::nothrow_t&) _NOEXCEPT;
                                     ^
  /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/new:190:74: note: candidate function not viable: requires 2 arguments, but 3 were provided
  _LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_AVAILABILITY_SIZED_NEW_DELETE void  operator delete(void* __p, std::size_t __sz) _NOEXCEPT;
                                                                           ^
  /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/new:221:40: note: candidate function not viable: requires 2 arguments, but 3 were provided
  inline _LIBCPP_INLINE_VISIBILITY void  operator delete  (void*, void*) _NOEXCEPT {}
                                         ^
  /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/new:187:36: note: candidate function not viable: requires single argument '__p', but 3 arguments were provided
  _LIBCPP_OVERRIDABLE_FUNC_VIS void  operator delete(void* __p) _NOEXCEPT;
                                     ^
  In file included from src/main.cpp:1:
  /usr/local/include/python3.7m/pybind11/pybind11.h:1011:9: error: call to unavailable function 'operator delete': introduced in macOS 10.12
          ::operator delete(p, s);
          ^~~~~~~~~~~~~~~~~
  /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/new:190:74: note: candidate function has been explicitly made unavailable
  _LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_AVAILABILITY_SIZED_NEW_DELETE void  operator delete(void* __p, std::size_t __sz) _NOEXCEPT;
                                                                           ^
  /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/new:221:40: note: candidate function not viable: no known conversion from 'pybind11::size_t' (aka 'unsigned long') to 'void *' for 2nd argument; take the address of the argument with &
  inline _LIBCPP_INLINE_VISIBILITY void  operator delete  (void*, void*) _NOEXCEPT {}
                                         ^
  /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/new:188:36: note: candidate function not viable: no known conversion from 'pybind11::size_t' (aka 'unsigned long') to 'const std::nothrow_t' for 2nd argument
  _LIBCPP_OVERRIDABLE_FUNC_VIS void  operator delete(void* __p, const std::nothrow_t&) _NOEXCEPT;
                                     ^
  note: candidate function not viable: no known conversion from 'pybind11::size_t' (aka 'unsigned long') to 'std::align_val_t' for 2nd argument
  /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/new:187:36: note: candidate function not viable: requires single argument '__p', but 2 arguments were provided
  _LIBCPP_OVERRIDABLE_FUNC_VIS void  operator delete(void* __p) _NOEXCEPT;
                                     ^
  3 errors generated.
  error: command 'clang' failed with exit status 1

  ----------------------------------------
  Failed building wheel for python-example
  Running setup.py clean for python-example
Failed to build python-example
Installing collected packages: python-example
  Running setup.py install for python-example ... error
    Complete output from command /usr/local/opt/python/bin/python3.7 -u -c "import setuptools, tokenize;__file__='/private/var/folders/7l/5r4qgkms4vb3xm6ktxdvh1l80000gn/T/pip-req-build-9f8udd0w/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /private/var/folders/7l/5r4qgkms4vb3xm6ktxdvh1l80000gn/T/pip-record-yvb3nloo/install-record.txt --single-version-externally-managed --compile:
    running install
    running build
    running build_ext
    clang -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/System/Library/Frameworks/Tk.framework/Versions/8.5/Headers -I/usr/local/include -I/usr/local/opt/openssl/include -I/usr/local/opt/sqlite/include -I/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/include/python3.7m -c /var/folders/7l/5r4qgkms4vb3xm6ktxdvh1l80000gn/T/tmpkd6a1ugc.cpp -o var/folders/7l/5r4qgkms4vb3xm6ktxdvh1l80000gn/T/tmpkd6a1ugc.o -std=c++17
    clang -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/System/Library/Frameworks/Tk.framework/Versions/8.5/Headers -I/usr/local/include -I/usr/local/opt/openssl/include -I/usr/local/opt/sqlite/include -I/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/include/python3.7m -c /var/folders/7l/5r4qgkms4vb3xm6ktxdvh1l80000gn/T/tmpywf858_h.cpp -o var/folders/7l/5r4qgkms4vb3xm6ktxdvh1l80000gn/T/tmpywf858_h.o -fvisibility=hidden
    building 'python_example' extension
    creating build
    creating build/temp.macosx-10.14-x86_64-3.7
    creating build/temp.macosx-10.14-x86_64-3.7/src
    clang -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/System/Library/Frameworks/Tk.framework/Versions/8.5/Headers -I/usr/local/include/python3.7m -I/Users/stevescott/Library/Python/3.7/include/python3.7m -I/usr/local/include -I/usr/local/opt/openssl/include -I/usr/local/opt/sqlite/include -I/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/include/python3.7m -c src/main.cpp -o build/temp.macosx-10.14-x86_64-3.7/src/main.o -stdlib=libc++ -mmacosx-version-min=10.7 -DVERSION_INFO="0.0.1" -std=c++17 -fvisibility=hidden
    In file included from src/main.cpp:1:
    In file included from /usr/local/include/python3.7m/pybind11/pybind11.h:49:
    In file included from /usr/local/include/python3.7m/pybind11/attr.h:13:
    /usr/local/include/python3.7m/pybind11/cast.h:579:34: error: aligned allocation function of type 'void *(unsigned long, enum std::align_val_t)' is only available on macOS 10.14 or newer
                            vptr = ::operator new(type->type_size,
                                     ^
    /usr/local/include/python3.7m/pybind11/cast.h:579:34: note: if you supply your own aligned allocation functions, use -faligned-allocation to silence this diagnostic
    In file included from src/main.cpp:1:
    /usr/local/include/python3.7m/pybind11/pybind11.h:1009:9: error: no matching function for call to 'operator delete'
            ::operator delete(p, s, std::align_val_t(a));
            ^~~~~~~~~~~~~~~~~
    note: candidate function not viable: requires 2 arguments, but 3 were provided
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/new:188:36: note: candidate function not viable: requires 2 arguments, but 3 were provided
    _LIBCPP_OVERRIDABLE_FUNC_VIS void  operator delete(void* __p, const std::nothrow_t&) _NOEXCEPT;
                                       ^
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/new:190:74: note: candidate function not viable: requires 2 arguments, but 3 were provided
    _LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_AVAILABILITY_SIZED_NEW_DELETE void  operator delete(void* __p, std::size_t __sz) _NOEXCEPT;
                                                                             ^
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/new:221:40: note: candidate function not viable: requires 2 arguments, but 3 were provided
    inline _LIBCPP_INLINE_VISIBILITY void  operator delete  (void*, void*) _NOEXCEPT {}
                                           ^
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/new:187:36: note: candidate function not viable: requires single argument '__p', but 3 arguments were provided
    _LIBCPP_OVERRIDABLE_FUNC_VIS void  operator delete(void* __p) _NOEXCEPT;
                                       ^
    In file included from src/main.cpp:1:
    /usr/local/include/python3.7m/pybind11/pybind11.h:1011:9: error: call to unavailable function 'operator delete': introduced in macOS 10.12
            ::operator delete(p, s);
            ^~~~~~~~~~~~~~~~~
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/new:190:74: note: candidate function has been explicitly made unavailable
    _LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_AVAILABILITY_SIZED_NEW_DELETE void  operator delete(void* __p, std::size_t __sz) _NOEXCEPT;
                                                                             ^
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/new:221:40: note: candidate function not viable: no known conversion from 'pybind11::size_t' (aka 'unsigned long') to 'void *' for 2nd argument; take the address of the argument with &
    inline _LIBCPP_INLINE_VISIBILITY void  operator delete  (void*, void*) _NOEXCEPT {}
                                           ^
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/new:188:36: note: candidate function not viable: no known conversion from 'pybind11::size_t' (aka 'unsigned long') to 'const std::nothrow_t' for 2nd argument
    _LIBCPP_OVERRIDABLE_FUNC_VIS void  operator delete(void* __p, const std::nothrow_t&) _NOEXCEPT;
                                       ^
    note: candidate function not viable: no known conversion from 'pybind11::size_t' (aka 'unsigned long') to 'std::align_val_t' for 2nd argument
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/new:187:36: note: candidate function not viable: requires single argument '__p', but 2 arguments were provided
    _LIBCPP_OVERRIDABLE_FUNC_VIS void  operator delete(void* __p) _NOEXCEPT;
                                       ^
    3 errors generated.
    error: command 'clang' failed with exit status 1

    ----------------------------------------
Command "/usr/local/opt/python/bin/python3.7 -u -c "import setuptools, tokenize;__file__='/private/var/folders/7l/5r4qgkms4vb3xm6ktxdvh1l80000gn/T/pip-req-build-9f8udd0w/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /private/var/folders/7l/5r4qgkms4vb3xm6ktxdvh1l80000gn/T/pip-record-yvb3nloo/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /private/var/folders/7l/5r4qgkms4vb3xm6ktxdvh1l80000gn/T/pip-req-build-9f8udd0w/

最佳答案

我在 Mac OS 上的 pybind11 项目遇到了同样的问题。

我无法找出根本原因,但找到了解决方法:我通过删除 -std=c++17 禁用了 C++17 cpp 标志来自列表here .

因此,我没有收到您提到的相同错误,而是将它们作为警告。这不是一个合适的解决方案,我真的很想看到一个真正的解释,但至少我已经编译了我的源代码。

更新:
eudoxos在他的评论中指出,他们开了一个 issue在 pybind11 的 github 页面上与此相关,修复应该在下一个版本中。

关于macos - 在 macos 上从 pybind11 文档构建 python_example 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57456419/

相关文章:

linux - RPM - 安装时间参数

c# - 编译器构建错误 : The call is ambiguous between the following methods or properties

java - 为什么Java中Integer对象的计数速度比int慢

c++ - C1202 : recursive type or function dependency context too complex

objective-c - NSTableView非法数据源

c++ - 如何将我的程序添加到 macOS 文件和文件夹右键菜单?

java - Ant 将文件复制到叶目录

c# - 编译器错误1 : constructor contains more than 0 args

mysql - 如何在我的 mac 上启动后自动启动 zend 服务器

cocoa - 确定终止的子进程未捕获哪个信号