导入用Boost.Python创建的模块时出错

2024-06-17 15:05:58 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用Boost.Python制作了一个模块

#include <boost/python.hpp>

double product(const long a,  const double x){
  return a*x;
}

void square(const long n, const double* x, double* x2){
  for(long i=0; i<n; ++i){
    x2[i]=x[i]*x[i];
  }
}

BOOST_PYTHON_MODULE(test)
{
  boost::python::def("product", product);
  boost::python::def("square", square);
}

我使用以下方法编译:

g++ test.cpp -fPIC -shared -I/usr/include/python2.7 -lpython2.7 -lboost_python -o libtest.so

不幸的是,当我尝试导入模块时,我收到以下错误消息:

ImportError: dynamic module does not define init function (initlibwrapper)

谢谢


Tags: 模块testreturnincludedefproductlongdouble