概述
更新:<> p>所以我已经用C++ {a1}用docs编译我的C++代码,并且在输入i接收信息:时,好像模块正在成功导入,当我查询^ {< CD1>}时
Docstring: Add two numbers.
Type: builtin_function_or_method
然而,当我实际调用函数assignment1.sum(1,2)时,Python内核会立即死亡,不会再出现“kernel deired,restarting”的错误消息。在#include
static PyObject * assignment1_add(PyObject *self, PyObject *args)
{
int *a, *b;
int sum;
if (!PyArg_ParseTuple(args, "ii", &a, &b))
return NULL;
sum = *a + *b;
return PyLong_FromLong(sum);
}
static PyMethodDef Assignment1Methods[] = {
{"add", assignment1_add, METH_VARARGS, "Add two numbers."},
{NULL, NULL, 0, NULL} /* Sentinel */
};
static struct PyModuleDef assignment1module = {
PyModuleDef_HEAD_INIT,
"assignment1", /* name of module */
NULL, /* module documentation, may be NULL */
-1, /* size of per-interpreter state of the module,
or -1 if the module keeps state in global variables. */
Assignment1Methods
};
PyMODINIT_FUNC PyInit_assignment1(void)
{
PyObject *m;
m = PyModule_Create(&assignment1module);
if (m == NULL)
return NULL;
return m;
}
int
main(int argc, char *argv[])
{
wchar_t *program = Py_DecodeLocale(argv[0], NULL);
if (program == NULL) {
fprintf(stderr, "Fatal error: cannot decode argv[0]n");
exit(1);
}
/* Add a built-in module, before Py_Initialize */
PyImport_appendInittab("assignment1", PyInit_assignment1);
/* Pass argv[0] to the Python interpreter */
Py_SetProgramName(program);
/* Initialize the Python interpreter. Required. */
Py_Initialize();
/* Optionally import the module; alternatively,
import can be deferred until the embedded script
imports it. */
PyImport_ImportModule("assignment1");
PyMem_RawFree(program);
return 0;
}
关于我下一步应该在哪里查找问题的原因有什么建议吗?在
最后
以上就是清爽丝袜为你收集整理的python编译器acanda_从Python调用(AcANDA)C++函数的全部内容,希望文章能够帮你解决python编译器acanda_从Python调用(AcANDA)C++函数所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复