diff --git a/m4/prog-cc-c-o.m4 b/m4/prog-cc-c-o.m4
index a31a4a414..bb60b39a9 100644
--- a/m4/prog-cc-c-o.m4
+++ b/m4/prog-cc-c-o.m4
@@ -31,7 +31,9 @@ AC_CACHE_CHECK(
       break
     fi
   done
-  rm -f core conftest*
+  rm -f -r a.out a.exe b.out conftest.$ac_ext conftest.$ac_objext \
+    conftest.dSYM conftest1.$ac_ext conftest1.$ac_objext conftest1.dSYM \
+    conftest2.$ac_ext conftest2.$ac_objext conftest2.dSYM
   unset am_i])
 if test "$am_cv_prog_cc_c_o" != yes; then
    # Losing compiler, so override with the script.
