diff --git a/src/archive.cc b/src/archive.cc
index 9170ca3ad..4a6211e00 100644
--- a/src/archive.cc
+++ b/src/archive.cc
@@ -1,3 +1,5 @@
+#include <cerrno>
+#include <algorithm>
 #include <vector>
 
 #include <sys/types.h>
diff --git a/src/pathlocks.cc b/src/pathlocks.cc
index 78aae26bd..93f456ace 100644
--- a/src/pathlocks.cc
+++ b/src/pathlocks.cc
@@ -1,3 +1,5 @@
+#include <cerrno>
+
 #include <fcntl.h>
 
 #include "pathlocks.hh"
diff --git a/src/references.cc b/src/references.cc
index 8934d5306..be432665b 100644
--- a/src/references.cc
+++ b/src/references.cc
@@ -1,3 +1,4 @@
+#include <cerrno>
 #include <map>
 
 #include <sys/types.h>
diff --git a/src/util.cc b/src/util.cc
index f2cdb1d72..bedd031de 100644
--- a/src/util.cc
+++ b/src/util.cc
@@ -1,4 +1,6 @@
 #include <iostream>
+#include <cerrno>
+#include <cstdio>
 
 #include <sys/types.h>
 #include <sys/stat.h>