diff --git a/src/build/Common.gmake b/src/build/Common.gmake
index cfe4c2b802b2714f9fa7f09ed93d376f7e93cf00..1ced56dcac43d96ddeca4fba498f95191f0ebbd8 100644
--- a/src/build/Common.gmake
+++ b/src/build/Common.gmake
@@ -216,9 +216,13 @@ endif
 BUILDPATH	?=	$(BUILD)
 
 gcc_machine		:= $(findstring mingw32,$(shell ${CC} -dumpmachine))
+gcc_w64                 := $(findstring w64,$(shell ${CC} -dumpmachine))
 ifeq ($(gcc_machine),mingw32)
  os		:= Win32
- CFLAGS	+=	-DMSVCRT_VERSION=0x0800 -m32
+ CFLAGS	+=	-DMSVCRT_VERSION=0x0800 -m32 -DDISABLE_MKSTEMP_DEFINE
+ ifeq ($(gcc_w64),w64)
+  CFLAGS += -DDISABLE_MKSTEMP_DEFINE
+ endif
  LDFLAGS+=	-m32
  WINDRESFLAGS+=	-Fpe-i386
 endif
diff --git a/src/xpdev/genwrap.c b/src/xpdev/genwrap.c
index c1fee56bd8014b2016d388ea00ddd3497d5982b4..f2d6b9369327651e67053f5f1b8db699e4bbc67a 100644
--- a/src/xpdev/genwrap.c
+++ b/src/xpdev/genwrap.c
@@ -671,6 +671,8 @@ long xp_random(int n)
 /* There may be a native GNU C Library function to this...					*/
 /****************************************************************************/
 #if !defined(_MSC_VER) && !defined(__BORLANDC__) && !defined(__WATCOMC__)
+#ifdef __GNUC__
+#if (__GNUC__ < 5)
 char* ultoa(ulong val, char* str, int radix)
 {
 	switch(radix) {
@@ -728,6 +730,8 @@ char* _ui64toa(uint64_t val, char* str, int radix)
 	return str;
 }
 #endif
+#endif
+#endif
 
 /****************************************************************************/
 /* Write the version details of the current operating system into str		*/
diff --git a/src/xpdev/genwrap.h b/src/xpdev/genwrap.h
index 3b725ec39ffe75e38ae894d6c0c772b5cb09b8b1..765d7a550f84c73464fe2ff4aa76eec6c829a93e 100644
--- a/src/xpdev/genwrap.h
+++ b/src/xpdev/genwrap.h
@@ -232,10 +232,14 @@ extern "C" {
 #endif
 
 #if !defined(_MSC_VER) && !defined(__BORLANDC__) && !defined(__WATCOMC__)
+#ifdef __GNUC__
+#if (__GNUC__ < 5)
 	DLLEXPORT char* ultoa(ulong, char*, int radix);
 	DLLEXPORT char* _i64toa(int64_t, char*, int radix);
 	DLLEXPORT char* _ui64toa(uint64_t, char*, int radix);
 #endif
+#endif
+#endif
 
 #if defined(__unix__)
 	DLLEXPORT char*	strupr(char* str);