boost_python hello示例不起作用
我正在尝试让BoostPython的HelloWorld示例正常工作。我使用的是boost_python hello示例不起作用,python,c++,boost,boost-python,Python,C++,Boost,Boost Python,我正在尝试让BoostPython的HelloWorld示例正常工作。我使用的是OSX、boost1.55和python2.7 这是我的hello.cpp #include <boost/python/module.hpp> #include <boost/python/def.hpp> char const* greet() { return "hello, world"; } BOOST_PYTHON_MODULE(hello_ext) { usin
OSX
、boost1.55
和python2.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);
}
当我试图通过importhello将其导入python时,我得到以下错误:
ImportError:动态模块未定义初始化函数(inithello)
有什么想法吗?发现BOOST\u PYTHON\u模块中的名称必须与库的名称匹配,所以我将链接步骤改为
g++ -shared -Wl, -o hello_ext.so hello.o -L/usr/lib -L/usr/local/lib -lpython2.7 -lboost_python
g++ -shared -Wl, -o hello_ext.so hello.o -L/usr/lib -L/usr/local/lib -lpython2.7 -lboost_python