using namespace boost::python;
struct World{
void set(std::string msg) { this->msg = msg; }
std::string greet() { return msg; }
std::string msg;
};
BOOST_PYTHON_MODULE(hello)
{
class_<World>("World")
.def("greet", &World::greet)
.def("set", &World::set)
;
}
Run Code Online (Sandbox Code Playgroud)
编译并构建好
~/boost$ g++ -fPIC -I/usr/include/python2.6 -c hello.cpp
~/boost$ g++ -shared hello.o -o hello.so
Run Code Online (Sandbox Code Playgroud)
但是当从python端导入时,出错了.
>>> import hello.so
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: ./hello.so: undefined symbol: _ZNK5boost6python7objects21py_function_impl_base9max_arityEv
>>>
Run Code Online (Sandbox Code Playgroud)
有谁能够帮我?提前致谢.
我理解调用函数(1)而不是函数(1)(2),它是如何工作的?
功能(1)(2)(3)(4)也可以吗?