一、写一个cpp
这个cpp的功能是 “加法器”,extern “C”的存在是因为python 的ctype可以调用C但是没有Cplustype~~~所以,~~~#include "/home/oujie/anaconda3/envs/pytorch-master/include/python3.7m/Python.h"
#功能实现在这个函数中
extern "C"
int add_func(int a,int b)
{
return a+b;
}
#下面的这些是调用相关的API把数据格式进行转换,让python可以调用,这也是python的头文件里面的定义好的
extern "C"
static PyObject *_add_func(PyObject *self, PyObject *args)
{
int _a,_b;
int res;
if (!PyArg_ParseTuple(args, "ii", &_a, &_b))
return NULL;
res = add_func(_a, _b);
return PyLong_FromLong(res);
}
extern "C"
static PyMethodDef CppModu