Extension module import error with MinGW, SWIG, and distutils

Phil Schmidt pschmidt at omnimn.com
Fri Aug 9 09:33:56 EDT 2002


Here's where I'm at with this so far:

I dumped SWIG for the moment to simplify things, and am using a simple
example (spammodule) from the distutils documentation. Everything
builds and installs ok, but I still get the import error described in
my previous post.

Using depends.exe and objdump, I can see that spammodule.pyd wants a
DLL named "c:winntsystem32python22.dll", which would be correct but
for the lack of the "\" path separators. I've looked at spammodule.o,
and there's no reference to such a DLL, therefore I conclude that the
problem is at the link stage. Here's the link command that distutils
is producing:

c:\MinGW\bin\gcc.exe
	-mno-cygwin
	-mdll
	-static
	-s build\temp.win32-2.2\Release\spammodule.o
	build\temp.win32-2.2\Release\spammodule.def
	-Lc:\progra~1\python22\libs
	-lpython22
	-o build\lib.win32-2.2\spammodule.pyd
	-v

and here's the actual linker invocation that results:

Reading specs from c:/MinGW/bin/../lib/gcc-lib/mingw32/2.95.3-6/specs
gcc version 2.95.3-6 (mingw special)
 c:\MinGW\bin\..\lib\gcc-lib\mingw32\2.95.3-6\..\..\..\..\mingw32\bin\ld.exe
	--dll
	-Bstatic
	-e _DllMainCRTStartup at 12
	-o build\lib.win32-2.2\spammodule.pyd
	-s c:/MinGW/bin/../lib/gcc-lib/mingw32/2.95.3-6/../../../dllcrt2.o
	-Lc:\progra~1\python22\libs
	-Lc:/MinGW/bin/../lib/gcc-lib/mingw32/2.95.3-6
	-Lc:/MinGW/bin/../lib/gcc-lib -L/mingw/lib/gcc-lib/mingw32/2.95.3-6
	-Lc:/MinGW/bin/../lib/gcc-lib/mingw32/2.95.3-6/../../../../mingw32/lib
	-L/mingw/lib/gcc-lib/mingw32/2.95.3-6/../../../../mingw32/lib
	-Lc:/MinGW/bin/../lib/gcc-lib/mingw32/2.95.3-6/../../..
	-L/mingw/lib/gcc-lib/mingw32/2.95.3-6/../../..
	build\temp.win32-2.2\Release\spammodule.o
	build\temp.win32-2.2\Release\spammodule.def
	-lpython22
	-lmingw32
	-lgcc
	-lmoldname
	-lmsvcrt
	-luser32
	-lkernel32
	-ladvapi32
	-lshell32
	-lmingw32
	-lgcc
	-lmoldname
	-lmsvcrt

Nothing here jumps out at me as being obvious, so I'm still stuck. I
will continue my investigation however...

If anyone has any ideas about what the problem might be, please
enlighten me!

pschmidt at omnimn.com (Phil Schmidt) wrote in message news:<69413f9.0208020512.56014eb6 at posting.google.com>...
> I've been slaving away (ok, not quite, but my head is about ready to
> burst!) trying to create an extension module on a Win2K machine, using
> MinGW, SWIG, and distutils. I've been working with a very simple
> example, just for the sake of learning the ropes, and I am now to the
> point where, when I attempt to import my extension module, I get the
> following traceback:
> 
> >>> import MyDemo
> Traceback (most recent call last):
>   File "<pyshell#0>", line 1, in ?
>     import MyDemo
> ImportError: DLL load failed: The specified module could not be found.
> 
> 
> Here's a summary of the steps I followed to create the MyDemo module:
> 
> 1) I manually ran SWIG to create the wrapper file (because if I let
> distutils call SWIG, it overwrites my C source file (and yes, I saw
> the posts about that, so I need to update my distutils...))
> 
> 2) I then run distutils, which, except for a couple mild warnings
> about some SWIG functions being defined but not used, runs without
> errors and creates a MyDemo.pyd file.
> 
> 3) I copy the .pyd file to my Python22/DLLs directory, then try to use
> it and get the error described above.
> 
> 4) I ran the depends.exe utility on my .pyd file, and it says that the
> "WINNTSYSTEM32PYTHON22.DLL" file is missing. The full path reported
> for this file is
> "c:\gnu_demo\simpledemo\build\lib.win32-2.2\WINNTSYSTEM32PYTHON22.DLL".
> Of course, this is incorrect, but I don't know how to fix it.
> 
> 5) As a test, I copied/renamed python22.dll to the path reported in
> step (4), and tried again, with the same DLL load error.
> 
> So, now I'm stumped (and frustrated)! It appears from the posts here
> that it is possible to make this work, but somehow I'm missing
> something.
> 
> I would be grateful if anyone could offer any suggestions!
> 
> Here are the files I'm working with right now:
> 
> ## demo.c ##
> ---------------------------------
> int MyDemo(int x)
> 	{
> 	return x*(1-x);
> 	}
> 
> 
> 
> ## demo.h ##
> ---------------------------------
> int MyDemo(int x);
> 
> 
> 
> ## demo.i ##
> ---------------------------------
> /* File : example.i */
> %module MyDemo
> 
> %{
> #include "demo.h"
> %}
> 
> int MyDemo(int x);
> 
> 
> ## setup.py ##
> ---------------------------------
> from distutils.core import setup, Extension
> 
> setup (name = "MyDemo",
>        version = "0.1",
>        description = "A Test!",
>        author = "Phil Schmidt",
>        author_email = "pschmidt at omnimn.com",
>        ext_modules = [Extension("MyDemo", ["demo.c", "demo_wrap.c"])]
>       )



More information about the Python-list mailing list