Can Python-2.2 on Windows be Extended using the MingW C compiler?
Chen
chenpuqing at 163.net
Mon Mar 17 21:48:01 EST 2003
"John Stevens" <john.stevens2 at hp.com> wrote in message
news:Xns93419595F8B27johnstevens2hpcom at 16.105.248.153...
> Hi,
>
> I'm trying to write a cross platform program using Python.
>
> I've written an extension module in C that compiles and works on
> Linux, and want to try to compile it and use it on Windows.
>
> Does anybody know if you can take the standard Python Distribution
> for Windows, and extend it using a C module that was compiled using
> the free MingW C compiler?
>
> Failing that, does anybody have any instructions for compiling Python
> using the MingW compiler?
>
> Thanks,
> John S.
This site, http://sebsauvage.net/python/mingw.html, give a good tutorial of
how to make python modules with MingW.
The following is my note and experiment for it:
The library Python22.lib should be converted to binutils format
(libPython22.a) firstly. 'dlltool' performs this aproach, with the help of a
program called 'pexports'.
Cygwin is helpful. It includes MingW, w32api and many other useful things.
And it's easier to install and use than the stand-alone MingW packages.
The following sample program is compiled and linked to MingW, on cygwin:
//Compile commands:
//gcc hellomodule.c -c -mno-cygwin -Id:/Python22/include
//gcc -shared hellomodule.o hellomodule.def -o
hello.pyd -Ld:/python22/libs -lpython22 -mno-cygwin
//source file (hellomodule.c):
#include <Python.h>
static PyObject *sayhello(PyObject *self)
{
return Py_BuildValue("s", "Hello, Python World!");
}
static PyMethodDef hellomethods[] = {
{"say", sayhello, METH_VARARGS},
{NULL, NULL}
};
DL_EXPORT(void) inithello(){
printf("Hello\n");
Py_InitModule("hello", hellomethods);
}
And a .def file is recommended.
//def file ( hellomodule.def ):
EXPORTS
inithello
Chen
More information about the Python-list
mailing list