利用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()
新聞熱點
疑難解答