diff -r 74eb9c51d64e Lib/_pyio.py --- a/Lib/_pyio.py Thu Oct 20 16:33:39 2016 -0400 +++ b/Lib/_pyio.py Fri Oct 21 06:38:50 2016 +0900 @@ -13,8 +13,13 @@ from _thread import allocate_lock as Lock except ImportError: from _dummy_thread import allocate_lock as Lock -if sys.platform in {'win32', 'cygwin'}: +if sys.platform == 'win32': from msvcrt import setmode as _setmode +elif sys.platform == 'cygwin': + import ctypes + _cygwin1 = ctypes.PyDLL('cygwin1.dll') + def _setmode(fd, mode): + return _cygwin1._setmode(ctypes.c_int(fd), ctypes.c_int(mode)) else: _setmode = None diff -r 74eb9c51d64e Lib/ctypes/__init__.py --- a/Lib/ctypes/__init__.py Thu Oct 20 16:33:39 2016 -0400 +++ b/Lib/ctypes/__init__.py Fri Oct 21 06:38:50 2016 +0900 @@ -427,7 +427,8 @@ if _os.name == "nt": pythonapi = PyDLL("python dll", None, _sys.dllhandle) elif _sys.platform == "cygwin": - pythonapi = PyDLL("libpython%d.%d.dll" % _sys.version_info[:2]) + pythonapi = PyDLL("libpython%d.%d%s.dll" % + (_sys.version_info[:2] + tuple(_sys.abiflags))) else: pythonapi = PyDLL(None) diff -r 74eb9c51d64e Lib/distutils/unixccompiler.py --- a/Lib/distutils/unixccompiler.py Thu Oct 20 16:33:39 2016 -0400 +++ b/Lib/distutils/unixccompiler.py Fri Oct 21 06:38:50 2016 +0900 @@ -81,6 +81,7 @@ xcode_stub_lib_format = dylib_lib_format if sys.platform == "cygwin": exe_extension = ".exe" + dylib_lib_extension = '.dll.a' def preprocess(self, source, output_file=None, macros=None, include_dirs=None, extra_preargs=None, extra_postargs=None):