Werner LEMBERG cited Nelson Beebe:
> Builds with C++ compilers fail in compiling getopt.c; it is too bad
> that that simple file could not have been written more portably. It
> has been the cause of C++ build failures on several other packages.
>
> I'll analyze his failure reports
FWIW, the getopt version from 1998 needed the following patches to make
in work in C++. Taken from GNU gperf. Maybe that might help you.
Bruno
getopt.c is a modified version of the getopt.c found in the glibc snapshot
on 1998-04-14. Below the patch that has been applied to this file. The glibc
maintainer has been informed of these patches.
diff -c3 getopt.c.orig getopt.c
*** getopt.c.orig Sun Mar 8 16:06:55 1998
--- getopt.c Thu Apr 16 00:09:41 1998
***************
*** 201,207 ****
/* Avoid depending on library functions or files
whose names are inconsistent. */
! char *getenv ();
static char *
my_index (str, chr)
--- 201,208 ----
/* Avoid depending on library functions or files
whose names are inconsistent. */
! extern char *getenv ();
! extern int strncmp ();
static char *
my_index (str, chr)
getopt.h is a modified version of the getopt.h found in the glibc snapshot
on 1998-04-14. Below the patch that has been applied to this file. The glibc
maintainer has been informed of these patches.
diff -c3 getopt.h.orig getopt.h
*** getopt.h.orig Sat Jun 21 03:01:53 1997
--- getopt.h Mon Aug 28 12:36:27 2000
***************
*** 1,5 ****
/* Declarations for getopt.
! Copyright (C) 1989,90,91,92,93,94,96,97 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
--- 1,5 ----
/* Declarations for getopt.
! Copyright (C) 1989-1998, 2000 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
***************
*** 78,84 ****
struct option
{
! #if defined (__STDC__) && __STDC__
const char *name;
#else
char *name;
--- 78,84 ----
struct option
{
! #if (defined (__STDC__) && __STDC__) || defined (__cplusplus)
const char *name;
#else
char *name;
***************
*** 96,102 ****
#define required_argument 1
#define optional_argument 2
! #if defined (__STDC__) && __STDC__
#ifdef __GNU_LIBRARY__
/* Many other libraries have conflicting prototypes for getopt, with
differences in the consts, in stdlib.h. To avoid compilation
--- 96,108 ----
#define required_argument 1
#define optional_argument 2
! #if (defined (__STDC__) && __STDC__) || defined (__cplusplus)
! #ifdef __cplusplus
! /* SunOS4 declares getopt with the following prototype:
! extern int getopt (int argc, const char *const *argv, const char *shortopts);
! We cannot redeclare it when compiling C++ code. */
! #define getopt(x,y,z) getopt_long(x, y, z, (const struct option *) 0, (int *) 0)
! #else /* not __cplusplus */
#ifdef __GNU_LIBRARY__
/* Many other libraries have conflicting prototypes for getopt, with
differences in the consts, in stdlib.h. To avoid compilation
***************
*** 105,110 ****
--- 111,117 ----
#else /* not __GNU_LIBRARY__ */
extern int getopt ();
#endif /* __GNU_LIBRARY__ */
+ #endif /* __cplusplus */
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,
_______________________________________________
bug-gnulib mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/bug-gnulib