检查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()
输出: