我正在尝试在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/