boost python简单实例

来源:互联网 发布:购物返利软件 编辑:程序博客网 时间:2024/05/29 17:16

利用boost中的python模块可以转化c++代码用于python调用

//hello_ext.cpp#include <boost/python.hpp>char const* greet(){   return "hello, world";}BOOST_PYTHON_MODULE(hello_ext){    using namespace boost::python;    def("greet", greet);}

然后在终端中:

g++ hello_ext.cpp -o hello_ext.so -shared -fPIC -I/usr/include/python2.7 -lboost_python

便可以在python中调用

import hello_extprint hello_ext.greet()


0 0
原创粉丝点击