[Distutils] Extending Python under Cygwin

Norman Vine nhv at cape.com
Tue Aug 26 11:17:12 EDT 2003

Oleksandr writes:
> 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,  1098-1100):
> Mark Lutz. Programming Python, O'REILLY.  Second  Edition.
> At the bottom of this message you can see these programs for your convenience.
> 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
> steps:
> 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

use gcc -shared instead of ld

you will also need to link with the Python Library as Win32 does not
allow undefined symbols

For example using your test file < named as hello_py,c >

<550> tmp
$ gcc -shared -o hello.dll hello_py.c -I/usr/include/Python2.2 /lib/python2.2/config/libpython2.2.dll.a

<551> tmp
$ ls *.dll

<552> tmp
$ python
Python 2.2.3 (#1, Jun  8 2003, 14:58:23)
[GCC 3.2 20020927 (prerelease)] on cygwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import hello
>>> dir(hello)
['__doc__', '__file__', '__name__', 'message']
>>> hello.message
<built-in function message>
>>> hello.message("Hi There")
'Hello, Hi There'



More information about the Distutils-SIG mailing list