diff --git a/src/w_wad.c b/src/w_wad.c
index 9c97c72f8ce8c23a6c28aa52590040ccc2b4e7e1..8693dd40fb70c9cffab4be6d3fd7dce7375dffa1 100644
--- a/src/w_wad.c
+++ b/src/w_wad.c
@@ -26,22 +26,6 @@
 #include "lzf.h"
 #endif
 
-#ifndef _MSC_VER
-#ifndef _LARGEFILE64_SOURCE
-#define _LARGEFILE64_SOURCE
-#endif
-#endif
-
-#ifndef _LFS64_LARGEFILE
-#define _LFS64_LARGEFILE
-#endif
-
-#ifndef _FILE_OFFSET_BITS
-#define _FILE_OFFSET_BITS 0
-#endif
-
-#include "zlib.h"
-
 #include "doomdef.h"
 #include "doomstat.h"
 #include "doomtype.h"
@@ -79,6 +63,24 @@ int	snprintf(char *str, size_t n, const char *fmt, ...);
 #define O_BINARY 0
 #endif
 
+#ifdef HAVE_ZLIB
+#ifndef _MSC_VER
+#ifndef _LARGEFILE64_SOURCE
+#define _LARGEFILE64_SOURCE
+#endif
+#endif
+
+#ifndef _LFS64_LARGEFILE
+#define _LFS64_LARGEFILE
+#endif
+
+#ifndef _FILE_OFFSET_BITS
+#define _FILE_OFFSET_BITS 0
+#endif
+
+#include "zlib.h"
+#endif
+
 
 typedef struct
 {
diff --git a/src/w_wad.h b/src/w_wad.h
index 4a15b23b1924e5c9fe4890052364662003fcb979..8baf061adce3982a185ff1c9b35489802aad6d9d 100644
--- a/src/w_wad.h
+++ b/src/w_wad.h
@@ -154,7 +154,9 @@ size_t W_LumpLength(lumpnum_t lumpnum);
 
 boolean W_IsLumpWad(lumpnum_t lumpnum); // for loading maps from WADs in PK3s
 
+#ifdef HAVE_ZLIB
 void zerr(int ret); // zlib error checking
+#endif
 
 size_t W_ReadLumpHeaderPwad(UINT16 wad, UINT16 lump, void *dest, size_t size, size_t offset);
 size_t W_ReadLumpHeader(lumpnum_t lump, void *dest, size_t size, size_t offest); // read all or a part of a lump