diff --git a/src/getpass.c b/src/getpass.c
index a2854cd16e3c41f94c316566989cb8ba5a629079..eb210460ec0e834c53249af33378b376a9dbb6f7 100644
--- a/src/getpass.c
+++ b/src/getpass.c
@@ -94,8 +94,8 @@ char *getpass_r(const char *prompt, char *buffer, size_t buflen)
 #endif
 
 /* The last #include file should be: */
-#ifdef CURLDEBUG
-#include "../lib/memdebug.h"
+#if defined(CURLDEBUG) && defined(CURLTOOLDEBUG)
+#include "memdebug.h"
 #endif
 
 char *getpass_r(const char *prompt, char *buffer, size_t buflen)
diff --git a/src/homedir.c b/src/homedir.c
index fedbdb8fcc2f024edbc70b0231de36be471d7e30..3ec196a7eafe071324ad529cf28037b753c9a05b 100644
--- a/src/homedir.c
+++ b/src/homedir.c
@@ -42,8 +42,8 @@
 
 #include "homedir.h"
 
-#ifdef CURLDEBUG
-#include "../lib/memdebug.h"
+#if defined(CURLDEBUG) && defined(CURLTOOLDEBUG)
+#include "memdebug.h"
 #endif
 
 static
diff --git a/src/main.c b/src/main.c
index 6cc264b24dbb91f8ec9bf14a3d08bc16848d476b..9c915203c788e24c0ccf29eefe35dacd2fb17d66 100644
--- a/src/main.c
+++ b/src/main.c
@@ -107,6 +107,9 @@
 
 /* The last #include file should be: */
 #ifdef CURLDEBUG
+#ifndef CURLTOOLDEBUG
+#define MEMDEBUG_NODEFINES
+#endif
 /* This is low-level hard-hacking memory leak tracking and similar. Using
    the library level code from this client-side is ugly, but we do this
    anyway for convenience. */
diff --git a/src/urlglob.c b/src/urlglob.c
index b7f56192c0a7cad5b8536bb83494895e93f090a9..582ec1b0b07e9cb90dc497eaa5fe1a268b0ab5cf 100644
--- a/src/urlglob.c
+++ b/src/urlglob.c
@@ -35,9 +35,8 @@
 
 #include "urlglob.h"
 
-
-#ifdef CURLDEBUG
-#include "../lib/memdebug.h"
+#if defined(CURLDEBUG) && defined(CURLTOOLDEBUG)
+#include "memdebug.h"
 #endif
 
 typedef enum {