extending python with a C-written dll

Jean-Baptiste PERIN jb_perin at yahoo.fr
Mon Dec 20 15:23:03 CET 2004


I'm trying to make a windows dll reachable from a python script .. and 
I'm encountering troubles during link step ..

I use "lcc" to compile and link
I use python 2.3 under win XP

Here's the compile command which seems to work well :
lcclnk.exe -entry inithello -dll -o hello.dll hello.obj -L 
"C:\python23\libs" python23.lib

Here's the link command which fails:
lcclnk.exe -entry inithello -dll -o hello.dll hello.obj -L 
"C:\python23\libs" python23.lib

Here are the errors :
Error c:\...\plugins\hello.c 14 undefined reference to __imp__Py_BuildValue
Error c:\...\plugins\hello.c 46 undefined reference to __imp__Py_InitModule4

Here's the C code which compile but does not link :

#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__},

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

Can anyone help me?

More information about the Python-list mailing list