[Distutils] SWIG+distutils+Windows???
Michel Van den Bergh
michel.vandenbergh@luc.ac.be
Thu Jan 4 05:33:01 2001
Ok, Thanks for everybody's help and especially for the tips contained in
the post below. I managed to make my extension! In the end it was easy!
I did the following.
(1) I downloaded the .def file mentioned in the post below.
(2) I made the cygwin/mingw compatible import library using the
procedure mentioned in the post below (I don't understand why this
import library isn't part of the standard Python distribution! I guess
many people who only use windows occasionally will use cygwing/mingw
since it is free.)
(3) I used
python setup.py build_ext -cmingw32
Before I had used -ccygwin. This compiled but produced an unloadable
library. Of course you need to download the mingw compiler. I used the
crtdll version. Afterwards I read that it had been better to use the
msvcrt version.
(4) The command in (3) gave some errors since mingw32 does not seem to
support all posix functions. I fixed this and then everything compiled
and linked smoothly.
(5) Now I had a library which loaded fine. However when I accessed
global c variables in python (SWIG makes these visible) then I got a
horrible crash. The solution was simply to write accessor functions for
these global variables (shouldn't have used global variables anyway:-).
Maybe this problem would not have occurred with the msvcrt version of
the compiler. I don't know.
It would be nice to put this procedure in a FAQ somewhere.
Best regards,
Michel
=====================================
Linux: the choice of a GNU generation
Rene Liebscher wrote:
>
> 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