c++ - 在MacOS上,简单pybind示例的编译失败

标签 c++ compiler-errors macos-catalina pybind11

我正在尝试在pybind11文档中实现simple add function example。我正在使用默认的Mac python3(3.7.7),并通过pybind11安装了pip3 install pybind11
有一个example.cpp文件:

#include <pybind11/pybind11.h>


int add(int i, int j)
{
        return i + j;
}

PYBIND11_MODULE(example, m)
{
        m.doc() = "pybind11 example plugin"; //optional module docstring
        m.def("add", &add, "A function which adds two numbers");
}
我正在尝试使用the default command they give for macos进行编译:
c++ -O3 -Wall -shared -std=c++11 -undefined dynamic_lookup `python3 -m pybind11 --includes` example.cpp -o example`python3-config --extension-suffix`
但是,这会导致一系列错误:
clang: error: unsupported option '--extension-suffix`'
clang: error: unknown argument: '-m'
clang: error: no such file or directory: '`python3'
clang: error: no such file or directory: 'pybind11'
我想念什么?我是否错过了设置pybind11的步骤?

最佳答案

原来,我不得不单独将pybind11添加到我的路径中:

export PYTHONPATH=$PYTHONPATH:/usr/local/include/python3.7m/pybind11/

关于c++ - 在MacOS上,简单pybind示例的编译失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62521569/

相关文章:

c++ - 如何使用 opencv contrib 模块编译 tldTracker

compiler-errors - CodevisionAVR类型定义

c# - Ajax控件工具包中缺少文件 list 错误?

c++ - 当 STL 容器对象的值不可复制构造时,如何将其附加/复制到另一个对象,例如标准::线程

bash - Broken Homebrew - 输入 "brew"+ 任何内容时出现回溯错误

c++ - Win32 DrawText 颜色和显示

c++ - 实例化后的显式特化

c++ - C++代码::Blocks “#include <array>” causing error

swift - 新项目使用 SwiftUI、XCode 12 和 Catalina 失败

python-3.x - MacOs Catalina AWS CLI 错误 "ImportError: cannot import name ' ssl' from 'urllib3.util.ssl_' "