c++生成、运行、调试python扩展(.pyd)
1.生成.pyd文件
1.pyd的本质
pyd就是dll(Linux上是.so)文件,并做了特殊约定:
(1)导出的模块函数名格式必须是 PyInit_模块名,如:
//test.cpp
#include <Python.h>
#include <iostream>
PyObject* PrintHello(PyObject *self, PyObject *args)
{
std::cout << "Hello, I am form c++" << std::endl;
Py_INCREF(Py_None);
return Py_None;
}
//描述方法
PyMethodDef Methods[] = {
{"PrintHelloFn", PrintHello, METH_VARARGS, "aSdasdasd"},
{NULL, NULL}
};
static struct PyModuleDef cModPyDem =
{
PyModuleDef_HEAD_INIT,
"PrintHello", /* name of module */
"", /* module documentation, may be NULL */
-1, /* size of per-interpreter state of the module, or -1 if the module keeps state in global variables. */
Methods
};
//函数名必须为这样的格式: PyInit_模块名
PyMODINIT_FUNC PyInit_PrintHello(vo