diff --git a/src/interfaces/ecpg/test/expected/preproc-strings.c b/src/interfaces/ecpg/test/expected/preproc-strings.c
index a26817968de..55859b624eb 100644
--- a/src/interfaces/ecpg/test/expected/preproc-strings.c
+++ b/src/interfaces/ecpg/test/expected/preproc-strings.c
@@ -18,6 +18,16 @@
 #line 3 "strings.pgc"
 /* exec sql begin declare section */
 #line 1 "strings.h"
+/* This extern silences headerscheck warnings with some gcc versions */
+  
+		   
+		   
+		   
+		   
+		   
+		   
+		   
+
 	   
 		   
 		   
@@ -29,7 +39,10 @@
 
 #line 5 "strings.pgc"
 
-#line 1 "strings.h"
+#line 2 "strings.h"
+ extern char * s1 , * s2 , * s3 , * s4 , * s5 , * s6 , * s7 , * s8 ;
+ 
+#line 11 "strings.h"
  char * s1 , * s2 , * s3 , * s4 , * s5 , * s6 , * s7 , * s8 ;
 /* exec sql end declare section */
 #line 5 "strings.pgc"
diff --git a/src/interfaces/ecpg/test/preproc/strings.h b/src/interfaces/ecpg/test/preproc/strings.h
index edb5be5339e..71581d6f94a 100644
--- a/src/interfaces/ecpg/test/preproc/strings.h
+++ b/src/interfaces/ecpg/test/preproc/strings.h
@@ -1,3 +1,13 @@
+/* This extern silences headerscheck warnings with some gcc versions */
+extern char *s1,
+		   *s2,
+		   *s3,
+		   *s4,
+		   *s5,
+		   *s6,
+		   *s7,
+		   *s8;
+
 char	   *s1,
 		   *s2,
 		   *s3,
diff --git a/src/tools/gen_keywordlist.pl b/src/tools/gen_keywordlist.pl
index 6ec83ff33f9..8825b4476ac 100644
--- a/src/tools/gen_keywordlist.pl
+++ b/src/tools/gen_keywordlist.pl
@@ -169,7 +169,16 @@ printf $kwdef qq|static %s\n|, $f;
 
 # Emit the struct that wraps all this lookup info into one variable.
 
-printf $kwdef "static " if !$extern;
+if ($extern)
+{
+	# This redundant extern declaration is needed to silence headerscheck
+	# warnings with some gcc versions.
+	printf $kwdef "extern const ScanKeywordList %s;\n\n", $varname;
+}
+else
+{
+	printf $kwdef "static ";
+}
 printf $kwdef "const ScanKeywordList %s = {\n", $varname;
 printf $kwdef qq|\t%s_kw_string,\n|, $varname;
 printf $kwdef qq|\t%s_kw_offsets,\n|, $varname;
