【发布时间】:2019-02-22 12:47:03
【问题描述】:
我在 XCode 上开发时遇到了这个问题。在网上找不到任何东西。我什至不知道这个问题是与 XCode 有关还是一般问题。
所以这是我的示例代码:
#include "myModule.h"
#include <Python/Python.h>
int Cfib(int n){
if (n<2){
return n;
}
else{
return Cfib(n-1)+Cfib(n-2);
}
}
static PyObject* fib(PyObject* self, PyObject* args){
int n;
if (!PyArg_ParseTuple(args, "i", &n)){
return NULL;
}
return Py_BuildValue("i", Cfib(n));
}
static PyObject* version(PyObject* self){
return Py_BuildValue("s", "Version 1.0");
}
static PyMethodDef myMethods[] = {
{"fib", fib, METH_VARARGS, "Calculate the fibonacci numbers."},
{"version", (PyCFunction)version, METH_NOARGS, "Tells us the version of our module."},
{NULL, NULL, 0, NULL}
};
static struct PyModuleDef myModule = {
PyModuleDef_HEAD_INIT, // Use of undeclared indentifier PyModuleDef_HEAD_INIT
"myModule",
"Fibnoacci Module",
-1,
myMethods
};
有谁知道该怎么做才能拥有 ** PyModuleDef_HEAD_INIT** ?我可以声明克服的默认方法头定义值是多少?
还是应该转向 Linux 环境进行进一步开发?
谢谢。
【问题讨论】: