本文介绍了在升压蟒蛇招呼程序导入错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#include <boost/python.hpp>
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)
    ;
}

编译并生成确定

~/boost$ g++ -fPIC -I/usr/include/python2.6 -c hello.cpp 
~/boost$ g++ -shared hello.o -o hello.so

但是,当从侧面蟒蛇进口,遇到错误。

But when import from python side, got error.

>>> import hello.so
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: ./hello.so: undefined symbol: _ZNK5boost6python7objects21py_function_impl_base9max_arityEv
>>>

有人能帮助我吗?先谢谢了。

Can anybody help me? Thanks in advance.

推荐答案

通过解决了这个http://stackoverflow.com/questions/1771063/help-needed-with-boost-python

g++ -c -fPIC hello.cpp -o hello.o
g++ -shared -Wl,-soname,hello.so -o hello.so  hello.o -lpython2.6 -lboost_python

做的把戏我。我希望这是尽可能清楚我是这个挣扎了约一个半小时,现在;)

did the trick for me. I hope this is as clear as possible as i was struggling with this for about half an hour now ;)

这篇关于在升压蟒蛇招呼程序导入错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-21 22:25