-extern StgWord GHCziTopHandler_runIO_closure[];
-extern StgWord GHCziTopHandler_runNonIO_closure[];
-#define runIO_closure GHCziTopHandler_runIO_closure
-#define runNonIO_closure GHCziTopHandler_runNonIO_closure
+// When producing Windows DLLs the we need to know which symbols are in the
+// local package/DLL vs external ones.
+//
+// Note that RtsAPI.h is also included by foreign export stubs in
+// the base package itself.
+//
+#if defined(mingw32_HOST_OS) && defined(__PIC__) && !defined(COMPILING_BASE_PACKAGE)
+__declspec(dllimport) extern StgWord base_GHCziTopHandler_runIO_closure[];
+__declspec(dllimport) extern StgWord base_GHCziTopHandler_runNonIO_closure[];
+#else
+extern StgWord base_GHCziTopHandler_runIO_closure[];
+extern StgWord base_GHCziTopHandler_runNonIO_closure[];
+#endif
+
+#define runIO_closure base_GHCziTopHandler_runIO_closure
+#define runNonIO_closure base_GHCziTopHandler_runNonIO_closure