--- a/libfuse/lib/fuse_dirents.cpp
+++ b/libfuse/lib/fuse_dirents.cpp
@@ -16,6 +16,8 @@
 #include <stdlib.h>
 #include <string.h>
 
+#undef dirent64
+#undef getdents64
 
 /* 32KB - same as glibc getdents buffer size */
 #define DENTS_BUF_EXPAND_SIZE (1024 * 32)
--- a/libfuse/lib/mount_util.c
+++ b/libfuse/lib/mount_util.c
@@ -25,6 +25,9 @@
 #include <sys/mount.h>
 #include <sys/param.h>
 
+#undef dirent64
+#undef getdents64
+
 #ifdef __NetBSD__
 #define umount2(mnt, flags) unmount(mnt, (flags == 2) ? MNT_FORCE : 0)
 #define mtab_needs_update(mnt) 0
--- a/libfuse/include/fuse_dirents.hpp
+++ b/libfuse/include/fuse_dirents.hpp
@@ -30,6 +30,9 @@
 #include <sys/types.h>
 #include <unistd.h>
 
+#undef dirent64
+#undef getdents64
+
 struct fuse_dirents_t
 {
   kvec_t(char)     data;
--- a/libfuse/util/mount_util.c
+++ b/libfuse/util/mount_util.c
@@ -25,6 +25,9 @@
 #include <sys/mount.h>
 #include <sys/param.h>
 
+#undef dirent64
+#undef getdents64
+
 #ifdef __NetBSD__
 #define umount2(mnt, flags) unmount(mnt, (flags == 2) ? MNT_FORCE : 0)
 #define mtab_needs_update(mnt) 0
--- a/Makefile
+++ b/Makefile
@@ -220,7 +220,7 @@
 	$(CXX) $(CXXFLAGS) $(TESTS_FLAGS) $(INC_FLAGS) $(MFS_FLAGS) $(CPPFLAGS) -c $< -o $@
 
 $(BUILDDIR)/preload.so: $(BUILDDIR)/stamp tools/preload.c
-	$(CC) -shared -fPIC $(CFLAGS) -o $@ tools/preload.c
+	$(CC) -shared -fPIC $(CFLAGS) $(CPPFLAGS) -o $@ tools/preload.c
 
 preload: $(BUILDDIR)/preload.so
 
