[Distutils] Extending Python under Cygwin

Oleksandr ozhmuds at tulane.edu
Tue Aug 26 09:47:42 EDT 2003

Dear Sir/Madam,

My name is Oleksandr Zhmudskyy and I am working at Tulane University
(Center for 
Computational Science).
I have a problem with Extending Python when I try to use GNU software.  
I installed Cygwin shell on PC and try to repeat example from Lutz's
book (p, 
Mark Lutz. Programming Python, O'REILLY.  Second  Edition.
At the bottom of this message you can see these programs for your
The only difference is that path to the Python folder is changed.  
This example is working Ok on Unix machine (IRIX 6.5) after the next two

1. gcc -g -c hello.c -I/usr/local/include/python2.2 -o hello.o
2. ld -shared hello.o -o hello.so

 Here I deliberately use command line (not Makefile) in order to
simplify the 
question.   At the first step file hello.o is created and on the second
one file 
hello.so. And everything is working.

Under the Cygwin shell on PC the first step is Ok:
 gcc hello.c -g -c -I/usr/include/python2.3/ -shared -o hello.o

And I have object file hello.o but the second step gives me mistakes
like this:

$ ld hello.o -g  -I/usr/include/python2.3/  -shared -o hello.so

hello.o(.text+0x2a): In function
undefined reference to `PyArg_Parse'
hello.o(.text+0x4a):/home/AAZH/MarkLutz/hello.c:17: undefined reference
hello.o(.text+0x5c):/home/AAZH/MarkLutz/hello.c:18: undefined reference
hello.o(.text+0x6f):/home/AAZH/MarkLutz/hello.c:19: undefined reference
hello.o(.text+0xb8): In function
undefined reference to `Py_InitModule4'

Note that simple GUI applications that don't need Python Extending are
correctly on Cygwin (for example,  hello.py or some programs like this).

In general we don't need any paths like -I/usr/local/include/python2.2
-I/usr/include/python2.3/ because they are already installed by Python.  
I checked this.  Also on STI Python we can see this directly:

>>> import sys
>>> sys.path

And the same command on Cygwin (PC):

>>> import sys
>>> sys.path

Would you be so kind to help me?  The thing is that installation Python
Cygwin was done correctly: no mistakes.  Thank you beforehand.

O. Zhmudsky

import hello

print hello.message('C')
print hello.message('module ' + hello.__file__)

for i in range(3):
    print hello.message(str(i))

#include </usr/include/python2.3/Python.h>
#include <string.h>

/* module functions */
static PyObject *                                 /* returns object */
message(PyObject *self, PyObject *args)           /* self unused in
modules */
{                                                 /* args from python
call */
    char *fromPython, result[64];
    if (! PyArg_Parse(args, "(s)", &fromPython))  /* convert Python -> C
        return NULL;                              /* null=raise
exception */
    else {
        strcpy(result, "Hello, ");                /* build up C string
        strcat(result, fromPython);               /* add passed Python
string */
        return Py_BuildValue("s", result);        /* convert C -> Python

/* registration table  */
static struct PyMethodDef hello_methods[] = {
    {"message", message, 1},       /* method name, C func ptr,
always-tuple */
    {NULL, NULL}                   /* end of table marker */

/* module initializer */
void inithello()                       /* called on first import */
{                                      /* name matters if loaded
dynamically */
    (void) Py_InitModule("hello", hello_methods);   /* mod name, table
ptr */


More information about the Distutils-SIG mailing list