diff -Naur Python-3.8.0-orig/Include/pyport.h Python-3.8.0/Include/pyport.h
--- Python-3.8.0-orig/Include/pyport.h	2019-10-22 10:00:37.955903300 +0300
+++ Python-3.8.0/Include/pyport.h	2019-10-22 10:01:14.850968200 +0300
@@ -651,12 +651,12 @@
 */
 
 /*
-  All windows ports, except cygwin, are handled in PC/pyconfig.h.
+  Only MSVC windows ports is handled in PC/pyconfig.h.
 
-  Cygwin is the only other autoconf platform requiring special
+  Cygwin and Mingw is the only other autoconf platform requiring special
   linkage handling and it uses __declspec().
 */
-#if defined(__CYGWIN__)
+#if defined(__CYGWIN__) || defined(__MINGW32__)
 #       define HAVE_DECLSPEC_DLL
 #endif
 
@@ -667,21 +667,23 @@
 #                       define PyAPI_FUNC(RTYPE) __declspec(dllexport) RTYPE
 #                       define PyAPI_DATA(RTYPE) extern __declspec(dllexport) RTYPE
         /* module init functions inside the core need no external linkage */
-        /* except for Cygwin to handle embedding */
-#                       if defined(__CYGWIN__)
+        /* except for Cygwin/Mingw to handle embedding */
+#                       if defined(__CYGWIN__) || defined(__MINGW32__)
 #                               define PyMODINIT_FUNC __declspec(dllexport) PyObject*
-#                       else /* __CYGWIN__ */
+#                       else /* __CYGWIN__ || __MINGW32__*/
 #                               define PyMODINIT_FUNC PyObject*
-#                       endif /* __CYGWIN__ */
+#                       endif /* __CYGWIN__ || __MINGW32__*/
 #               else /* Py_BUILD_CORE */
         /* Building an extension module, or an embedded situation */
         /* public Python functions and data are imported */
         /* Under Cygwin, auto-import functions to prevent compilation */
         /* failures similar to those described at the bottom of 4.1: */
         /* http://docs.python.org/extending/windows.html#a-cookbook-approach */
-#                       if !defined(__CYGWIN__)
+#                       if defined(__CYGWIN__) || defined(__MINGW32__)
+#                               define PyAPI_FUNC(RTYPE) RTYPE
+#                       else
 #                               define PyAPI_FUNC(RTYPE) __declspec(dllimport) RTYPE
-#                       endif /* !__CYGWIN__ */
+#                       endif /* __CYGWIN__ || __MINGW32__*/
 #                       define PyAPI_DATA(RTYPE) extern __declspec(dllimport) RTYPE
         /* module init functions outside the core must be exported */
 #                       if defined(__cplusplus)
diff -Naur Python-3.8.0-orig/setup.py Python-3.8.0/setup.py
--- Python-3.8.0-orig/setup.py	2019-10-22 10:00:25.787881900 +0300
+++ Python-3.8.0/setup.py	2019-10-22 10:01:15.256568900 +0300
@@ -316,6 +316,9 @@
             raise ValueError("No source directory; cannot proceed.")
         self.srcdir = os.path.abspath(self.srcdir)
 
+        if MS_WINDOWS:
+            self.compiler.define_macro("Py_BUILD_CORE_MODULE")
+
         # Detect which modules should be compiled
         self.detect_modules()
 
