【发布时间】:2015-01-30 14:13:51
【问题描述】:
我正在尝试让 boost python 工作的 hello world 示例。我正在使用OSX、boost 1.55 和python 2.7
这是我的hello.cpp
#include <boost/python/module.hpp>
#include <boost/python/def.hpp>
char const* greet()
{
return "hello, world";
}
BOOST_PYTHON_MODULE(hello_ext)
{
using namespace boost::python;
def("greet", greet);
}
我用以下两行编译它:
g++ -fPIC -I/usr/include/python2.7/ -I/usr/local/include/ -c hello.cpp
g++ -shared -Wl, -o hello.so hello.o -L/usr/lib -L/usr/local/lib -lpython2.7 -lboost_python
当我尝试通过 import hello.so 将其导入 python 时,我收到以下错误:
ImportError: dynamic module does not define init function (inithello)
有什么想法吗?
【问题讨论】:
标签: python c++ boost boost-python