0
我有一个非常简单的C++函数示例,我通过Boost.Python将其导出到python(2.7.13)。下面的代码:使用std :: string作为Boost.python导出函数的返回类型
#include <string>
#include <boost/python.hpp>
const char* greet()
{
return "hello, world!";
}
BOOST_PYTHON_MODULE(libhello)
{
using namespace boost::python;
def("hello_world", greet);
}
予编译OSX 10.10.5机器上
g++ -I ~/boost -L ~/boost/stage/lib\
-L /System/Library/Frameworks/Python.framework/Versions/Current\
-fpic export.cpp -shared -lboost_python -lPython -olibhello.so
它正确地产生libhello.so
,我可以然后在python使用
import libhello as lh
lh.hello_world() # correctly returns the string "hello, world"
然而,当我将C++文件中的返回类型greet
更改为std::string
,即
std::string greet(){...}
我正在在Python下列崩溃运行lh.hello_world()
后:
Fatal Python error: PyEval_SaveThread: NULL tstate
Abort trap: 6
和pyhton崩溃。任何想法为什么?它是否与非POD返回类型有关?
我可以确认'std :: string greet(){...}'对我来说工作正常' Ubuntu 17.4/g ++ - 6.3.0/boost 1.62',因此这必须与安装了类UNIX计算机上的内容有关。 – doqtor
@doqtor好的,谢谢!那么我会看到我身边发生了什么。 – vsoftco