With pyMinGW

A.B., Khalid abkhd at earth.co.jp
Wed Feb 22 23:37:49 EST 2006


bearophileHUGS at lycos.com wrote:
> Thank you for your answers, Khalid.
>
> > It seems you may be using an old version of pyMinGW,
>
> I have downloaded it yesterday from your site.
>
>
> > the relevant part dealing with include directories in zlib.mak
> > should read now as follows:
>
> I have checked, and that relevant part is the same in my zlib.mak.
>
>
> > but since the site stopped the hosting of zip files and since many
> > people do not download that particular file anyway when it was hosted
> > elsewhere, letting the file expire (inactive files are removed after
> > one week from last download), then I hope you'd agree it would be much
> > work for me to keep track of expired and unexpired files and so keep on
> > uploading the files.
>
> You can probably remove the dead link from your page.
> (Maybe I can build a complete package (with Tkinter, minGW and Swig
> too), and put it in some official Python site.)
>
>
> > As to your SWIG problem, then I suggest you look into the pyMinGW's
> > extensions' directory. There you will find two examples of building C
> > and CPP extensions using SWIG and MinGW.
>
> I don't want to use/waste too much of your time, I have succed with the
> C++ example, but the C example has given me some problems:
>
> C:\...\PyminGW\Python-2.4.2\MinGW\Extensions\pyExt_C_exmaple>python24
> setupMingW.py build --compile
> r=mingw32
> running build
> running build_ext
> building '_example' extension
> swigging example.i to example_wrap.c
> C:\...\PyminGW\swigwin-1.3.28\swig.exe -python -o example_wrap.c
> example.i
> C:\......\bin\gcc.exe -mno-cygwin -mdll -O2 -Wall -s
> -IC:\...\PyminGW\Python-2.4
> .2\include -IC:\...\PyminGW\Python-2.4.2\PC -c example_wrap.c -o
> build\temp.win32-2.4\Release\examp
> le_wrap.o
> example_wrap.c: In function `PySwigClientData_New':
> example_wrap.c:1205: warning: dereferencing type-punned pointer will
> break strict-aliasing rules
> example_wrap.c: In function `PySwigObject_own':
> example_wrap.c:1456: warning: dereferencing type-punned pointer will
> break strict-aliasing rules
> example_wrap.c:1456: warning: dereferencing type-punned pointer will
> break strict-aliasing rules
> example_wrap.c: In function `My_variable_set':
> example_wrap.c:2515: error: `My_variable' undeclared (first use in this
> function)
>
> Bye,
> bearophile


You are using the C example extension found in pyMinGW, right? It
builds fine here, of course using the "python setup.py build" command.

$ python setupMinGW.py build
running build
running build_ext
building '_example' extension
swigging example.i to example_wrap.c
d:\MISC\PROGRAMS\SWIG-1.3.21\swig.exe -python -o example_wrap.c
example.i
creating build
creating build\temp.win32-2.4
creating build\temp.win32-2.4\Release
e:\UTILIT~1\PROGRA~1\MINGW\BIN\gcc.exe -mno-cygwin -mdll -O2 -Wall -s
-IG:\PROJS\PY24\PYTHON\DIST\SRC\include
-IG:\PROJS\PY24\PYTHON\DIST\SRC\PC -c example_wrap.c -o
build\temp.win32-2.4\Release\example_wrap.o
example_wrap.c:187: warning: 'SWIG_Python_TypeDynamicCast' defined but
not used
example_wrap.c:199: warning: 'SWIG_Python_TypeName' defined but not
used
example_wrap.c:205: warning: 'SWIG_Python_TypeQuery' defined but not
used
example_wrap.c:551: warning: 'SWIG_Python_MustGetPtr' defined but not
used
example_wrap.c:559: warning: 'SWIG_Python_ConvertPacked' defined but
not used
e:\UTILIT~1\PROGRA~1\MINGW\BIN\gcc.exe -mno-cygwin -mdll -O2 -Wall -s
-IG:\PROJS\PY24\PYTHON\DIST\SRC\include
-IG:\PROJS\PY24\PYTHON\DIST\SRC\PC -c example.c -o
build\temp.win32-2.4\Release\example.o
writing build\temp.win32-2.4\Release\_example.def
creating build\lib.win32-2.4
e:\UTILIT~1\PROGRA~1\MINGW\BIN\gcc.exe -mno-cygwin -shared -s
build\temp.win32-2.4\Release\example_wrap.o
build\temp.win32-2.4\Release\example.o
build\temp.win32-2.4\Release\_example.def
-LG:\PROJS\PY24\PYTHON\DIST\SRC\libs
-LG:\PROJS\PY24\PYTHON\DIST\SRC\PCBuild -lpython24 -o
build\lib.win32-2.4\_example.pyd

And copying that _example.pyd from the build directory just created to
our current directory so that python can see it, we can load that
extension fine as well:

$ python -i
Python 2.4.2 (#67, Nov  8 2005, 10:12:11)
[GCC 3.4.2 (mingw-special)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import example as ex
>>> dir(ex)
['__builtins__', '__doc__', '__file__', '__name__', '_example',
'_newclass', '_object', '_swig_getattr', '_swig_setattr', 'cvar',
'fact', 'fib', 'get_time', 'hello', 'my_mod']
>>> ex.hello()
'Hi there!'
>>> ex.fact(4)
24
>>> 


Regards,
Khalid




More information about the Python-list mailing list