diff --git libgomp/config.h.in libgomp/config.h.in
index 226ac53..1ef51ca 100644
--- libgomp/config.h.in
+++ libgomp/config.h.in
@@ -1,5 +1,11 @@
 /* config.h.in.  Generated from configure.ac by autoheader.  */
 
+
+  #ifdef LIBGOMP_H
+  # error Must not #include "config.h" after #include "libgomp.h".
+  #endif
+
+
 /* Define to 1 if the target assembler supports .symver directive. */
 #undef HAVE_AS_SYMVER_DIRECTIVE
 
diff --git libgomp/configure libgomp/configure
index 8d03eb6..327bd1b 100755
--- libgomp/configure
+++ libgomp/configure
@@ -2592,6 +2592,7 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu
 ac_config_headers="$ac_config_headers config.h"
 
 
+
 # -------
 # Options
 # -------
@@ -11145,7 +11146,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 11148 "configure"
+#line 11149 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -11251,7 +11252,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 11254 "configure"
+#line 11255 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
diff --git libgomp/configure.ac libgomp/configure.ac
index 2e41ca8..b9a665f 100644
--- libgomp/configure.ac
+++ libgomp/configure.ac
@@ -4,6 +4,11 @@
 AC_PREREQ(2.64)
 AC_INIT([GNU Offloading and Multi Processing Runtime Library], 1.0,,[libgomp])
 AC_CONFIG_HEADER(config.h)
+AH_TOP([
+  #ifdef LIBGOMP_H
+  # error Must not #include "config.h" after #include "libgomp.h".
+  #endif
+])
 
 # -------
 # Options
diff --git libgomp/libgomp.h libgomp/libgomp.h
index 664e76b..6a05bbc 100644
--- libgomp/libgomp.h
+++ libgomp/libgomp.h
@@ -33,7 +33,12 @@
    that are part of the external ABI, and the lower case prefix "gomp"
    is used group items that are completely private to the library.  */
 
-#ifndef LIBGOMP_H 
+#ifndef LIBGOMP_H
+/* We #include "config.h" early, before we #define LIBGOMP_H, so that we can
+   use the latter to check in "config.h" that it's not being included again,
+   which might conflict with configuration changes done further down in
+   libgomp.h.  */
+#include "config.h"
 #define LIBGOMP_H 1
 
 #ifndef _LIBGOMP_CHECKING_
@@ -41,7 +46,6 @@
 #define _LIBGOMP_CHECKING_ 0
 #endif
 
-#include "config.h"
 #include "gstdint.h"
 #include "libgomp-plugin.h"
 
diff --git libgomp/oacc-cuda.c libgomp/oacc-cuda.c
index 86a2a77..115697d 100644
--- libgomp/oacc-cuda.c
+++ libgomp/oacc-cuda.c
@@ -26,9 +26,8 @@
    see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
    <http://www.gnu.org/licenses/>.  */
 
-#include "openacc.h"
-#include "config.h"
 #include "libgomp.h"
+#include "openacc.h"
 #include "oacc-int.h"
 
 void *
diff --git libgomp/oacc-int.h libgomp/oacc-int.h
index db0a937..7fd9e95 100644
--- libgomp/oacc-int.h
+++ libgomp/oacc-int.h
@@ -38,8 +38,8 @@
 #ifndef OACC_INT_H
 #define OACC_INT_H 1
 
+#include "libgomp.h"
 #include "openacc.h"
-#include "config.h"
 #include <stddef.h>
 #include <stdbool.h>
 #include <stdarg.h>
diff --git libgomp/oacc-mem.c libgomp/oacc-mem.c
index ce1905c..0d98a7f 100644
--- libgomp/oacc-mem.c
+++ libgomp/oacc-mem.c
@@ -26,9 +26,8 @@
    see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
    <http://www.gnu.org/licenses/>.  */
 
-#include "openacc.h"
-#include "config.h"
 #include "libgomp.h"
+#include "openacc.h"
 #include "gomp-constants.h"
 #include "oacc-int.h"
 #include <stdint.h>
diff --git libgomp/plugin/plugin-nvptx.c libgomp/plugin/plugin-nvptx.c
index 4b57833..fc5f298 100644
--- libgomp/plugin/plugin-nvptx.c
+++ libgomp/plugin/plugin-nvptx.c
@@ -31,8 +31,8 @@
    is not clear as to what that state might be.  Or how one might
    propagate it from one thread to another.  */
 
+#include "libgomp.h"
 #include "openacc.h"
-#include "config.h"
 #include "libgomp-plugin.h"
 #include "oacc-plugin.h"
 #include "gomp-constants.h"
diff --git libgomp/target.c libgomp/target.c
index e2dd0e0..dd6f74d 100644
--- libgomp/target.c
+++ libgomp/target.c
@@ -25,7 +25,6 @@
 
 /* This file contains the support of offloading.  */
 
-#include "config.h"
 #include "libgomp.h"
 #include "oacc-plugin.h"
 #include "oacc-int.h"
