Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
导入C++;Python中的dll失败_Python_Windows - Fatal编程技术网

导入C++;Python中的dll失败

导入C++;Python中的dll失败,python,windows,Python,Windows,在“扩展和嵌入Python解释器”中的以下文档中,我创建了一个VC项目,并成功创建了一个名为“spam_d.dll”的dll文件 主要代码是 static PyObject * spam_system(PyObject *self, PyObject *args) { const char *command; int sts; if (!PyArg_ParseTuple(args, "s", &command)) return NULL;

在“扩展和嵌入Python解释器”中的以下文档中,我创建了一个VC项目,并成功创建了一个名为“spam_d.dll”的dll文件

主要代码是

static PyObject *
spam_system(PyObject *self, PyObject *args)
{
    const char *command;
    int sts;

    if (!PyArg_ParseTuple(args, "s", &command))
        return NULL;
    sts = system(command);
    return Py_BuildValue("i", sts);
}

static PyMethodDef SpamMethods[] = {
    {"system",  spam_system, METH_VARARGS, "Execute a shell command."},
    {NULL, NULL, 0, NULL}        /* Sentinel */
};

PyMODINIT_FUNC
initspam(void)
{
    (void) Py_InitModule("spam", SpamMethods);
}
然后,我用python键入了以下命令:

导入垃圾邮件 [参考文献39003] 垃圾邮件系统(“pwd”) /SVN/Python/PCbuild 0 [参考文献39005]

它看起来工作正常。 但是当我将dll名称从spam_d.pyd重命名为spam.pyd时。Python找不到该模块

>>> import spam
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named spam
[39005 refs]
导入垃圾邮件 回溯(最近一次呼叫最后一次): 文件“”,第1行,在 ImportError:没有名为垃圾邮件的模块 [参考文献39005] 从第一种情况来看,python似乎可以正确设置“导入垃圾邮件”和“spam_d.pyd”之间的关系

python如何知道“spam”模块是“spam_d.pyd”,而不是“spam.pyd”


有没有任何文档提到过它。

python试图链接带有后缀_d.pyd的调试库,因为它是一个调试构建。要链接aganist spam.pyd,您需要一个发布版本。

“。初始化函数必须命名为initname(),其中name是模块的名称…”,但我不确定这是否是您问题的根源。“模块的名称”是spam\u d还是spam?我必须承认我很快阅读了问题,但您很快阅读了文档;-)。“只有当模块的初始化函数名为initspam()时,才能导入模块垃圾邮件,并且它应该调用Py_InitModule(),字符串“spam”作为其第一个参数…”和“按照惯例,它位于名为spam.c或spammodule.c的文件中。输出文件应称为spam.pyd(在发布模式下)或spam_d.pyd(在调试模式下)。”