[python-win32] Linking Python Libraries With GCC In WIndows XPUsing SWIG

Moore, Paul Paul.Moore at atosorigin.com
Tue Sep 23 10:33:10 EDT 2003


From: Steve Farris [mailto:sfarris at ll.mit.edu]
> (note:  I tried this with SWIG1.3.19 with the same results).

I used swig 1.3.19 and Python 2.3.

> swig -python example.i
> gcc -c -I<PythonPath>\include example.c example_wrap.c

No problem with these two

> gcc -shared -L<PythonPath>\libs\python22.LIB example.o example_wrap.o -o examplemodule.so 

Many problems here.

1. If you're using gcc (mingw, presumably, not cygwin???) with Python, you
   need to generate a libpython22.a and put it in your <PythonPath>\libs
   directory. Instructions are in the Python documentation, "Installing
   Python Modules", section 6.2.2. Run pexports then dlltool as shown.
2. -L sets the directory to search for libXXX.a when -lXXX is included.
   You want -L<PythonPath>\libs -lpython22.
3. The output module should be called _example.pyd, not examplemodule.so.
   Are you looking at Unix-targetted instructions?

The following command line works:

gcc -shared -LC:\Apps\Python\libs example.o example_wrap.o -lpython22 -o _example.pyd

Hope this helps,
Paul.



More information about the Python-win32 mailing list