diff --git a/tools/CIndex/CIndex.cpp b/tools/CIndex/CIndex.cpp
index 2b33a63b98305ea39fcabedce844de7a984cfaf9..01a4cdd0ae8625b65912660e732f8f75ad413141 100644
--- a/tools/CIndex/CIndex.cpp
+++ b/tools/CIndex/CIndex.cpp
@@ -19,6 +19,9 @@
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/System/Program.h"
 
+// Needed to define L_TMPNAM on some systems.
+#include <cstdio>
+
 using namespace clang;
 using namespace idx;