我正在一个项目中,使用pybind11将一堆C ++代码移植到python。我已经完成了几个模块,但是编译时总是出错。
源代码是:
namespace math {
typedef xyzMatrix<double> Matrix;
typedef xyzVector<double> Vector;
inline
void
dot_vector (Matrix const & m, Vector const & v, Vector & vr) {
// ommitted for brevity
}
};
该函数的书面绑定为:
m.def("dot_vector", &math::dot_vector,
py::arg("m"),
py::arg("v"),
py::arg("vr"));
请注意,执行函数地址无效,并且未重载了自由功能。我得到的错误是:
../math/math.cc:49:4: error: no matching member function for call to 'def'
m.def("dot_vector", &math::dot_vector,
~~^~~
pybind11/include/pybind11/pybind11.h:761:13: note: candidate template ignored: couldn't infer template argument 'Func'
module &def(const char *name_, Func &&f, const Extra& ... extra) {
我尝试将模板专门化为double
,但它似乎不起作用。需要明确的是,我已经能够获得模板化的类来进行编译。