diff --git a/src/modules/_Image_JPEG/image_jpeg.c b/src/modules/_Image_JPEG/image_jpeg.c
index 2eb072bbe107ba94349ae17690b23c142feb85de..fcff7b887dd90141a810fe18c98aef4438741e37 100644
--- a/src/modules/_Image_JPEG/image_jpeg.c
+++ b/src/modules/_Image_JPEG/image_jpeg.c
@@ -1,6 +1,3 @@
-#include "global.h"
-RCSID("$id: $");
-
 #include "config.h"
 
 #if !defined(HAVE_LIBJPEG)
@@ -9,10 +6,20 @@ RCSID("$id: $");
 
 #ifdef HAVE_JPEGLIB_H
 
+#define FILE void
+#define size_t unsigned int
 #include <jpeglib.h>
+#undef size_t
+#undef FILE
 
 #endif /* HAVE_JPEGLIB_H */
 
+#ifdef HAVE_STDLIB_H
+#undef HAVE_STDLIB_H
+#endif
+#include "global.h"
+RCSID("$id: $");
+
 #include "pike_macros.h"
 #include "object.h"
 #include "constants.h"