diff --git a/contrib/Chaco/main/Gmsh_exit.cpp b/contrib/Chaco/main/Gmsh_exit.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..eefa63932285987c86422390e7ee2d0148a97eb7
--- /dev/null
+++ b/contrib/Chaco/main/Gmsh_exit.cpp
@@ -0,0 +1,11 @@
+// Gmsh - Copyright (C) 1997-2008 C. Geuzaine, J.-F. Remacle
+//
+// See the LICENSE.txt file for license information. Please report all
+// bugs and problems to <gmsh@geuz.org>.
+
+#include <stdexcept>
+
+extern "C" void Gmsh_exit()
+{
+   throw std::runtime_error("Library Chaco wants to exit");
+}
diff --git a/contrib/Chaco/main/Gmsh_exit.h b/contrib/Chaco/main/Gmsh_exit.h
new file mode 100644
index 0000000000000000000000000000000000000000..ab9b44bad4601c5559d4cb5604f8a6f9212ea77d
--- /dev/null
+++ b/contrib/Chaco/main/Gmsh_exit.h
@@ -0,0 +1,13 @@
+// Gmsh - Copyright (C) 1997-2008 C. Geuzaine, J.-F. Remacle
+//
+// See the LICENSE.txt file for license information. Please report all
+// bugs and problems to <gmsh@geuz.org>.
+
+// Overload the printf statements in Chaco to write using Msg::Direct gmsh
+
+#ifndef _GMSH_EXIT_H_
+#define _GMSH_EXIT_H_
+
+int Gmsh_exit();
+
+#endif
diff --git a/contrib/Chaco/main/Gmsh_printf.cpp b/contrib/Chaco/main/Gmsh_printf.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..661cdb83b427ceb69f70c72d6a65a3a2e98d0079
--- /dev/null
+++ b/contrib/Chaco/main/Gmsh_printf.cpp
@@ -0,0 +1,18 @@
+// Gmsh - Copyright (C) 1997-2008 C. Geuzaine, J.-F. Remacle
+//
+// See the LICENSE.txt file for license information. Please report all
+// bugs and problems to <gmsh@geuz.org>.
+
+#include "../../../Common/Message.h"
+
+// Overload the printf statements in Chaco to write using Msg::Direct in gmsh
+
+extern "C" int Gmsh_printf(const char *fmt, ...)
+{
+  char str[1024];
+  va_list args;
+  va_start(args, fmt);
+  vsnprintf(str, sizeof(str), fmt, args);
+  va_end(args);
+  Msg::Direct(3, str);
+}
diff --git a/contrib/Chaco/main/Gmsh_printf.h b/contrib/Chaco/main/Gmsh_printf.h
new file mode 100644
index 0000000000000000000000000000000000000000..69e4ed1f3f37c207d8015ba687ccc7ab98bb14cf
--- /dev/null
+++ b/contrib/Chaco/main/Gmsh_printf.h
@@ -0,0 +1,14 @@
+// Gmsh - Copyright (C) 1997-2008 C. Geuzaine, J.-F. Remacle
+//
+// See the LICENSE.txt file for license information. Please report all
+// bugs and problems to <gmsh@geuz.org>.
+
+// Overload the printf statements in Chaco to write using Msg::Direct gmsh
+
+#ifndef _GMSH_PRINTF_H_
+#define _GMSH_PRINTF_H_
+
+#define printf Gmsh_printf
+int Gmsh_printf(const char *fmt, ...);
+
+#endif