Creating C modules for Python under Cygwin

Jason Tishler jason at tishler.net
Sat May 4 21:24:02 EDT 2002


Rick,

On Sat, May 04, 2002 at 10:39:16AM -0700, Richard P. Muller wrote:
> I'm having trouble creating Python modules from C under Cygwin. The
> process works fine under Linux, but I get a long list of undefined
> references (to PyArg_ParseTuple, PyArg_BuildValue, etc.) when I try to
> link under Cygwin.

Are you using the Cygwin Python that is part of the standard Cygwin
distribution?  Or, one that you built yourself?  The following assumes
the former.

> I found a reference in an archive of a Cygwin mailing list that claims I
> have to satisfy all of the undefined references under Cygwin. But it
> seems silly to link in the entire Python library in a tiny little
> module.

I don't believe that the above implies linking the "entire Python
library."  Instead one just needs to link against the import library
that corresponds to the Cygwin Python DLL core.  This is exactly how it
works for Win32 Python and other Windows DLLs too.

> This must work on some level, since people have managed to compile, for
> example, NumPy under Cygwin.

Yes, it does and for many, many other shared extensions too.

> Am I missing something here

Yes.

> or railing against the impossible?

No.

> Can someone give me pointers?

Yes, use Distutils to build your shared extension.  If you use this
method, then the "right things" will happen automatically.

Otherwise, you need to do the following when building your shared
extension:

1. during compilation specify -DUSE_DL_IMPORT

2. during linking specify -L/usr/lib/python2.2/config -lpython2.2

Jason





More information about the Python-list mailing list