diff --git a/lib/diagnostics.h b/lib/diagnostics.h
index 361b87bb8d764f7b03c0701a4b228919dbb652dc..8cc69c9442e3db0e9b3b0acfd693f3891d83a990 100644
--- a/lib/diagnostics.h
+++ b/lib/diagnostics.h
@@ -34,7 +34,9 @@
 #include <dlfcn.h>
 #endif
 
+#ifdef __cplusplus
 extern bool main_exited;
+#endif
 
 // some of the Android stuff below causes seg faults on some devices.
 // Disable by default.