I'm trying to implement the simple add function example in the pybind11
docs. I'm using the default mac python3
(3.7.7), and have installed pybind11
by pip3 install pybind11
.
There is an example.cpp
file:
#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");
}
I'm trying to compile this using 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`
This results in a series of errors, however:
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'
What am I missing? Did I miss a step setting up pybind11
?
It turns out that I had to add pybind11
to my path separately:
export PYTHONPATH=$PYTHONPATH:/usr/local/include/python3.7m/pybind11/