Index: common/getopt.cc
===================================================================
--- common/getopt.cc	(revision 14233)
+++ common/getopt.cc	(working copy)
@@ -75,7 +75,7 @@
    Also, when `ordering' is RETURN_IN_ORDER,
    each non-option ARGV-element is returned here.  */
 
-char *optarg;
+char *Xapian::Internal::optarg;
 
 /* Index in ARGV of the next element to be scanned.
    This is used for communication to and from the caller
@@ -90,7 +90,7 @@
    how much of ARGV has been scanned so far.  */
 
 /* 1003.2 says this must be 1 before any call.  */
-int optind = 1;
+int Xapian::Internal::optind = 1;
 
 /* Formerly, initialization of getopt depended on optind==0, which
    causes problems with re-calling getopt as programs generally don't
@@ -110,13 +110,13 @@
 /* Callers store zero here to inhibit the error message
    for unrecognized options.  */
 
-int opterr = 1;
+int Xapian::Internal::opterr = 1;
 
 /* Set to an option character which was unrecognized.
    This must be initialized on some systems to avoid linking in the
    system's own getopt implementation.  */
 
-int optopt = '?';
+int Xapian::Internal::optopt = '?';
 
 /* Describe how to deal with options that follow non-option ARGV-elements.
 
Index: common/gnu_getopt.h
===================================================================
--- common/gnu_getopt.h	(revision 14233)
+++ common/gnu_getopt.h	(working copy)
@@ -57,12 +57,18 @@
 
 #else
 
-extern "C" {
+namespace Xapian {
+namespace Internal {
 extern char *optarg;
 extern int optind;
 extern int opterr;
 extern int optopt;
 }
+}
+using Xapian::Internal::optarg;
+using Xapian::Internal::optind;
+using Xapian::Internal::opterr;
+using Xapian::Internal::optopt;
 
 struct option {
     const char *name;

