OVH Cloud OVH Cloud

étendre python avec une dll écrite en C

2 réponses
Avatar
Jean-Baptiste PERIN
Bonjour,

je cherche à faire une dll windows qui soit accessible depuis python
et j'ai un problème au link

Voici la commande de link :
---------------------------
lcclnk.exe -entry inithello -dll -o hello.dll hello.obj -L
"C:\python23\libs" python23.lib


Voici les erreurs :
-------------------
Error c:\...\plugins\hello.c 14 undefined referenc e to
__imp__Py_BuildValue
Error c:\...\plugins\hello.c 46 undefined reference to __imp__Py_InitModule4



Voici le code C qui compile mais qui ne link pas :
---------------------------------------------------

#include <Python.h>

PyObject *helloHello(PyObject *self, PyObject *args)
{
printf("Hello World!");
return Py_BuildValue("i", 1);
}

PyObject *helloHelloString(PyObject *self, PyObject *args)
{
return Py_BuildValue("s", "Hello World!");
}

static char MHello__doc__[] = "This is a simple Python C extension example";
static char Hello__doc__[] = "Prints in the console";
static char HelloString__doc__[] = "Returns message as string";

PyMethodDef helloMethods[] = {
{"Hello", helloHello, METH_VARARGS, Hello__doc__},
{"HelloString", helloHelloString, METH_VARARGS, HelloString__doc__},
{NULL, NULL}
};

void __declspec(dllexport) inithello()
{
(void)Py_InitModule3("hello", helloMethods, MHello__doc__);
}


Est-ce que qqu'un a une idée ?

2 réponses

Avatar
Amaury Forgeot d'Arc
Voici la commande de link :
---------------------------
lcclnk.exe -entry inithello -dll -o hello.dll hello.obj -L
"C:python23libs" python23.lib


Quel compilateur est-ce ?
Pour construire des extensions pour Python 2.3,
il faut utiliser le compilateur de Microsoft:
Visual C++ version 6.

--
Amaury

Avatar
jms


Voici la commande de link :
---------------------------
lcclnk.exe -entry inithello -dll -o hello.dll hello.obj -L
"C:python23libs" python23.lib



Quel compilateur est-ce ?
Pour construire des extensions pour Python 2.3,
il faut utiliser le compilateur de Microsoft:
Visual C++ version 6.

--
Amaury



Sans importance. L'auteur de la question a trouvé une
méthode pour effectuer la compilation au travers des outils
cygwin.

@+