Cygwin Python DLL and Shared Extension Patch

Jason Tishler
Thu Nov 9 06:44:00 GMT 2000

Attached is a patch that builds Cygwin Python with its core as a DLL --
similar to the way that one builds Win32 Python.  Once Cygwin Python
is built as a "shared library" (i.e., DLL), one can build extensions
using the same procedure as on other UNIX platforms that support shared
libraries.  It's as easy as copying Misc/, creating a file, make -f boot, make.

Actually, attached is two versions of the same patch.  The first one is
the real patch but requires autoconf.  The second one was generated after
I ran autoconf and hence only requires the more typical build environment.

Use the following procedure to patch and build Cygwin Python if you *have*

	$ tar -xvzf Python-2.0.tar.gz
	$ cd Python-2.0
	$ patch -p1 <../CygwinPython-2.0-minimal.patch
	$ autoheader
	$ autoconf
	$ configure --with-threads=no --with-libm= --with-suffix=.exe
	$ make
	$ make install

Use the following procedure to patch and build Cygwin Python if you *do not*
have autoconf:

	$ tar -xvzf Python-2.0.tar.gz
	$ gunzip CygwinPython-2.0-full.patch.gz
	$ cd Python-2.0
	$ patch -p1 <../CygwinPython-2.0-full.patch
	$ configure --with-threads=no --with-libm= --with-suffix=.exe
	$ make
	$ make install

To test out shared extensions, try the following:

	$ cd Demo/extend
	$ make_shared
	$ python
	Python 2.0 (#1, Nov  1 2000, 08:51:39)
	[GCC 2.95.2 19991024 (release-2)] on cygwin_nt-4.01
	Type "copyright", "credits" or "license" for more information.
	>>> import xx
	>>> dir(xx)
	['__doc__', '__file__', '__name__', 'bug', 'error', 'foo', 'new', 'roj']
	>>>, 3)

As a more realistic example, I was able to build python-ldap 1.10alpha3
( ) with the following minimal

	1. replaced #ifdef WIN32 with #if defined(WIN32) || defined(__CYGWIN__)
	   as described in
	2. added DL_EXPORT to init_ldap()

Note that there were no changes of any kind to the build files (i.e,,, and Modules/ or functionality changes
to the C source.

My goal is to ultimately submit the patch (redone against Python CVS) 
to the Python patch collector.  I am hoping interested people will help 
me refine the patch before submittal.

The following is an annotated ChangeLog for the patch:

Wed Nov  8 23:22:46 2000  Jason Tishler <>

	* Add autoconf variable SET_DLLLIBRARY.
	* (altbininstall): Enhance altbininstall rule to also
	install the Cygwin Python DLL.
	* (libainstall): Change libainstall rule to install

	Will installing LDLIBRARY instead of LIBRARY break other
	platforms?  The terse description of LDLIBRARY in
	seems to indicate that possibly the original build procedure
	should be been installing it instead of LIBRARY.  Anyway, I am
	very willing to change the patch to install both LDLIBRARY and
	LIBRARY (if they are different) or some other suitable solution.

	* Modules/ Add autoconf variable SET_DLLLIBRARY.
	* Modules/ ($(DLLLIBRARY)): Add $(DLLLIBRARY) rule to build
	the Cygwin Python DLL.

	Should the body of this rule be hidden in a shell script?  I have 
	stumbled across various platform specific scripts like BeOS/ar-fake
	that has me thinking that this may be desirable.  If not, then I will
	clean up the rule to use variables like LDSHARED instead of "gcc
	-shared", etc.

	* Modules/makesetup: Add shell variable module and default its value
	to "module".
	* Modules/makesetup: Add Cygwin specific definitions to set shell
	variables module, CygwinFlags, and CygwinLibs appropriately.

	Is it undesirable to put platform specific code in makesetup?

	* Modules/makesetup: Add .def to the list of known file types.
	* Modules/makesetup: Change object rule to include CygwinFlags.
	* Modules/makesetup: Change to use shell variable module instead of
	hardcoded "module".
	* Modules/makesetup: Change shared extension rule to include
	* acconfig.h: Add __CYGWIN__ guarded #defines for DL_IMPORT and

	Is there a better way of accomplishing this without affecting config.h
	on all other autoconf supported platforms too?

	* Add autoconf variable SET_DLLLIBRARY.
	* Add Cygwin case to set LDLIBRARY and SET_DLLLIBRARY

	I have chosen to call the import library libpython$(VERSION).dll.a
	and the DLL libpython$(VERSION).dll.  Recently there has been a
	proposal ( )
	to name Cygwin DLLs cygfoo.dll instead of libfoo.dll in order
	to avoid clashing with Win32 versions of the same DLL.  I have stayed
	with libpython2.0.dll because it is more consistent with the UNIX
	naming convention and because there is no (current) possibility of
	clashing with the Win32 Python DLL, python20.dll.  Nevertheless, I
	am willing to change the name of the Cygwin Python DLL, if desired.

	* Add Cygwin case to set MAKE_LDLIBRARY appropriately.
	* Add Cygwin case to set SO appropriately.
	* Add Cygwin case to set LDSHARED appropriately.

	Should LDSHARED contain more flags?  For example,
	-Wl,--enable-auto-image-base, etc.?

Any feedback is greatly appreciated.


Jason Tishler
Director, Software Engineering       Phone: +1 (732) 264-8770 x235
Dot Hill Systems Corporation         Fax:   +1 (732) 264-8798
82 Bethany Road, Suite 7             Email:
Hazlet, NJ 07730 USA                 WWW:
-------------- next part --------------
A non-text attachment was scrubbed...
Name: CygwinPython-2.0-full.patch.gz
Type: application/x-gzip
Size: 18882 bytes
Desc: not available
URL: <>

More information about the Cygwin mailing list