diff --git a/src/libcamera/include/media_object.h b/src/libcamera/include/media_object.h
index 950a33286690..00772fd11234 100644
--- a/src/libcamera/include/media_object.h
+++ b/src/libcamera/include/media_object.h
@@ -12,6 +12,15 @@
 
 #include <linux/media.h>
 
+/*
+ * In the GNU C Library, "major" and "minor" are defined by <sys/sysmacros.h>.
+ * GCC 7.3.0 also defines this in <sys/types.h> for historical compatibility.
+ * To prevent conflicting with the major() and minor() member functions we
+ * unconditionally undef these here.
+ */
+#undef major
+#undef minor
+
 namespace libcamera {
 
 class MediaDevice;
