用定义不正确的符号导入恐怖:尝试创建自定义C++模块时PyMeuleSeCuraTe2

2024-09-27 20:17:47 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图更新一个C++模块,与Python兼容。我使用make命令构建了模块,构建成功。但是,当我尝试运行该模块时,出现以下错误:

ImportError: /root/generator/exporters.so: undefined symbol: PyModule_Create2

我添加的代码如下:

#ifdef PY3K
static struct PyModuleDef exporters =
{
    PyModuleDef_HEAD_INIT,
    "exporters", /* 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. */
    exporters_methods
};

/*
 * Python calls this to let us initialize our module
 */
void PyInit_exporters() {
    (void) PyModule_Create(&exporters);
}
#else
/*
 *  Python calls this to let us initialize our module
 */
void initexporters() {
    (void) Py_InitModule("exporters", exporters_methods);
}
#endif

该代码适用于使用python2构建的模块,但不适用于python3。 我曾尝试查看是否正在使用调试版本进行构建,如许多答案中所述,但未能做到这一点。 请帮忙


Tags: 模块oftheto代码thismethodsmodule

热门问题