检查boost版本:dpkg -S /usr/include/boost/version.hpp
C++代码:
#include<string>
#include<boost/python.hpp>
using namespace std;
using namespace boost::python;
char const * greet()
{
return "hello,world";
}
BOOST_PYTHON_MODULE(hello_ext)
{
def("greet", greet);
}
编译:g++ -std=c++11 -fPIC test1.cpp -o hello_ext.so -shared -I/usr/include/python2.7 -lboost_python
切记生成的文件要与module同名。
python代码:
import hello_ext
print hello_ext.greet()输出:
![]()
版权声明:本文为qq_26045215原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。