利用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()
新闻热点
疑难解答