[Distutils] SWIG+distutils+Windows???

Rene Liebscher R.Liebscher@gmx.de
Thu Jan 4 03:57:00 2001


Michel Van den Bergh wrote:
> 
> Hi I am trying to generate an extension module using distutils on
> windows.
> I am using the plain vanilla command
> 
> python setup.py build_ext -ccygwin
> 
> (the corresponding command without the -ccygwin works fine on Linux).
> 
> The source for the extension module was generated by SWIG on Linux (as I
> don't have
> SWIG on windows).
> 
> Compiling seems to go fine but then I get a bunch of undefined symbols:
> 
> Cannot export init_hintmodule: symbol not defined
> build\temp.win32-2.0\Release\gtlevel\src\hint_wrap.o(.text+0x165):hint_wrap.c:
> undefined reference to `_imp__PyExc_NameError'
> build\temp.win32-2.0\Release\gtlevel\src\hint_wrap.o(.text+0x1f1):hint_wrap.c:
> undefined reference to `_imp__PyExc_NameError'
> build\temp.win32-2.0\Release\gtlevel\src\hint_wrap.o(.text+0x230):hint_wrap.c:
> undefined reference to `_imp__PyType_Type'
> build\temp.win32-2.0\Release\gtlevel\src\hint_wrap.o(.text+0x9e2):hint_wrap.c:
> undefined reference to `_imp___Py_NoneStruct'
> build\temp.win32-2.0\Release\gtlevel\src\hint_wrap.o(.text+0x9e9):hint_wrap.c:
> undefined reference to `_imp___Py_NoneStruct'
> build\temp.win32-2.0\Release\gtlevel\src\hint_wrap.o(.text+0xa22):hint_wrap.c:
> undefined reference to `_imp___Py_NoneStruct'
> build\temp.win32-2.0\Release\gtlevel\src\hint_wrap.o(.text+0xa29):hint_wrap.c:
> undefined reference to `_imp___Py_NoneStruct'
> build\temp.win32-2.0\Release\gtlevel\src\hint_wrap.o(.text+0xa99):hint_wrap.c:
> undefined reference to `_imp__PyExc_TypeError'
> build\temp.win32-2.0\Release\gtlevel\src\hint_wrap.o(.text+0xb3d):hint_wrap.c:
> undefined reference to `_imp__PyExc_TypeError'
> collect2: ld returned 1 exit status
> error: command 'gcc' failed with exit status 1
> 
> I have no idea what the problem is here. Is there anybody than can help?
> I suspect this must be trivial for a knowledgeable person.
> 
> The version numbers are as follows:
> gcc 2.95.2
> ld 2.10.90
> dllwrap 2.10.90
> 
I think the main problem is you are not using a special import library
for cygwin. 
All missing symbols are data stuctures.
Cygwin can obviously read only text (=code) information from foreign 
library formats.

So you have to build a special import library for cygwin.

1. create a def-file for python20.dll with all symbols (also the data
symbols)
You can find this def-file also at
http://www.informatik.htw-dresden.de/~liebschr/distutils-cygwin/python20.def
is was created with Pexports see also
http://starship.python.net/crew/kernr/mingw32/Notes.html

2. create a import library
dlltool --dllname python20.dll --def python20.def --output-lib
libpython20.a

3. place this file libpython20.a in your libs directory to the other
import library (Cygwinccompiler from distutils will choose the right
one.)


If you call 'nm libpython20.a' you should get a list of all symbols in
it.
There you find entries like this:
ds00510.o:
00000000 b .bss
00000000 d .data
00000000 i .idata$4
00000000 i .idata$5
00000000 i .idata$6
00000000 i .idata$7
00000000 t .text
00000000 T _Py_SetPythonHome              <============
         U __head_libpython20_a
00000000 I __imp__Py_SetPythonHome

These are normal function calls (it has a line ?????? T _function_name)

And you find entries like this:
ds00560.o:
00000000 b .bss
00000000 d .data
00000000 i .idata$4
00000000 i .idata$5
00000000 i .idata$6
00000000 i .idata$7
00000000 t .text
         U __head_libpython20_a
00000000 I __imp___Py_NoneStruct

These are data structures (without this T line.)

I hope these hints help you.


Kind regards

Rene Liebscher