To summarize so far: - The problem arises in /opt/csw/include/getopt.h, which is non-standard on Solaris. Not a problem gnulib is to be blamed for.
- It arises in C++ mode only. In C mode the header file works fine. - Joel Denny writes: > it starts to feel like /opt/csw/include/getopt.h's approach > of quickly giving up on determining the best getopt argument list is > easiest. However, for C++, it can't give up because there's no such thing > as an unspecified argument list. - Dagobert wants a small modification of his CSWlibgnugetopt package and not a complete reimplementation. So here's my suggestion. Change /opt/csw/include/getopt.h like this, and be done with it. All the __STDC__ checks can be removed. No one uses K&R C nowadays any more. Only ANSI/ISO C and C++ are relevant. $ diff -u getopt.h.csw getopt.h --- getopt.h.csw Mon Jan 18 11:40:07 2010 +++ getopt.h Mon Apr 26 00:48:56 2010 @@ -80,11 +80,7 @@ struct option { -#if defined (__STDC__) && __STDC__ const char *name; -#else - char *name; -#endif /* has_arg can't be an enum because some compilers complain about type mismatches in all the code that assumes it is an int. */ int has_arg; @@ -98,15 +94,14 @@ #define required_argument 1 #define optional_argument 2 -#if defined (__STDC__) && __STDC__ -#ifdef __GNU_LIBRARY__ +#if defined __GNU_LIBRARY__ || defined __sun /* Many other libraries have conflicting prototypes for getopt, with differences in the consts, in stdlib.h. To avoid compilation - errors, only prototype getopt for the GNU C library. */ + errors, only prototype getopt for the GNU C library and for Solaris. */ extern int getopt (int argc, char *const *argv, const char *shortopts); -#else /* not __GNU_LIBRARY__ */ +#else /* not __GNU_LIBRARY__ || __sun */ extern int getopt (); -#endif /* __GNU_LIBRARY__ */ +#endif /* __GNU_LIBRARY__ || __sun */ extern int getopt_long (int argc, char *const *argv, const char *shortopts, const struct option *longopts, int *longind); extern int getopt_long_only (int argc, char *const *argv, @@ -118,14 +113,7 @@ const char *shortopts, const struct option *longopts, int *longind, int long_only); -#else /* not __STDC__ */ -extern int getopt (); -extern int getopt_long (); -extern int getopt_long_only (); -extern int _getopt_internal (); -#endif /* __STDC__ */ - #ifdef __cplusplus } #endif