diff --git a/nt/Makefile.in b/nt/Makefile.in
index f9662183065..71d590b2c15 100644
--- a/nt/Makefile.in
+++ b/nt/Makefile.in
@@ -139,7 +139,7 @@ EMACS_MANIFEST = @EMACS_MANIFEST@
WINDRES = @WINDRES@
## Extra libraries to use when linking addpm.
-LIBS_ADDPM = -lole32 -luuid
+LIBS_ADDPM = -L../lib -lgnu -lole32 -luuid
## Compilation and linking flags
BASE_CFLAGS = $(C_SWITCH_SYSTEM) $(C_SWITCH_MACHINE) \
diff --git a/nt/cmdproxy.c b/nt/cmdproxy.c
index 8f4333e6139..8b2f18feade 100644
--- a/nt/cmdproxy.c
+++ b/nt/cmdproxy.c
@@ -28,6 +28,10 @@ You should have received a copy of the GNU General Public License
along with GNU Emacs. If not, see . */
#define DEFER_MS_W32_H
+/* We don't want to use the stdio-consolesafe redefinitions of *printf
+ functions, since (a) that pulls in stdio, which we don't want, see
+ below; and (b) we have our own implementations of *printf here. */
+#define OMIT_CONSOLESAFE 1
#include
#include
diff --git a/nt/ddeclient.c b/nt/ddeclient.c
index 11dcfb5a3c5..52cfbde21eb 100644
--- a/nt/ddeclient.c
+++ b/nt/ddeclient.c
@@ -17,6 +17,9 @@ You should have received a copy of the GNU General Public License
along with GNU Emacs. If not, see . */
#define DEFER_MS_W32_H
+/* We only ever use fprintf for a fixed usage message below, so the
+ stdio-consolesafe module is overkill. */
+#define OMIT_CONSOLESAFE 1
#include
#include
diff --git a/src/conf_post.h b/src/conf_post.h
index e946f6fc90b..99400d76210 100644
--- a/src/conf_post.h
+++ b/src/conf_post.h
@@ -397,7 +397,7 @@ extern int emacs_setenv_TZ (char const *);
: S_ISSOCK (mode) ? DT_SOCK : DT_UNKNOWN)
#endif /* MSDOS */
-#if defined WINDOWSNT
+#if defined WINDOWSNT && !(defined OMIT_CONSOLESAFE && OMIT_CONSOLESAFE == 1)
# if !defined _UCRT
# include
# include