首页 > 编程 > Python > 正文

boost python简单实例

2019-11-06 08:25:48
字体:
来源:转载
供稿:网友

利用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()


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表