[tlbuild] build failure: duplicated extern "C" definition of getopt() when compiling a C++ program

Vladimir Volovich vvv at vsu.ru
Sun Jun 6 23:04:40 CEST 2010


"KB" == Karl Berry writes:

 KB>     extern int getopt ( ) ;

 KB> Evidently your CC is not defining __cplusplus, which would have
 KB> avoided the error.  So what macro does it predefine?

it is predefining __cplusplus; the line which causes an error was line
number 140 in texk/kpathsea/getopt.h (before your change in r18529),
which is still present in this file:

#if defined (__STDC__) && __STDC__
...
#else /* not __STDC__ */
extern KPSEDLL int getopt (); <<<<< here

and the error is still present (on both Solaris and AIX).

apparently, on Solaris, the C compiler by default has __STDC__ defined
as 0, and this is documented in the cc(1) man page:

======================================
     -X[c|a|t|s]
          Specifies the degree of conformance to the ISO C stan-
          dard.  The value of -xc99 affects which version of the
          ISO C standard the -X option applies.

          c (conformance)
               Strictly conformant ISO C, without K&R C compati-
               bility extensions.  The compiler issues errors and
               warnings for programs that use non-ISO C con-
               structs.  The predefined macro __STDC__ has a
               value of 1 with the -Xc option.

          a    This is the default compiler mode. ISO C plus K&R
               C compatibility extensions, with semantic changes
               required by ISO C. Where K&R C and ISO C specify
               different semantics for the same construct, the
               compiler uses the ISO C interpretation. If the -Xa
               option is used in conjunction with the
               -xtransition option, the compiler issues warnings
               about the different semantics. The predefined
               macro __STDC__ has a value of 0 with the -Xa
               option.

          t (transition)
               This option uses ISO C plus K&R C compatibility
               extensions without semantic changes required by
               ISO C.  Where K&R C and ISO C specify different
               semantics for the same construct, the compiler
               uses the K&R C interpretation. If you use the -Xt
               option in conjunction with the -xtransition
               option, the compiler issues warnings about the
               different semantics. The predefined macro __STDC__
               has a value of zero with the -Xt option.

          s (K&R C)
               The compiler tries to warn about all language con-
               structs that have differing behavior between Sun
               ISO C and the K&R C. Invokes cpp for processing.
               __STDC__ is not defined in this mode.

          The predefined macro __STDC__ has the value 0 for -Xt
          and -Xa, and 1 for -Xc.  (It is not defined for -Xs.)
          All warning messages about differing behavior can be
          eliminated through appropriate coding; for example, use
          of casts can eliminate the integral promotion change
          warnings.
======================================

OTOH, the C++ compiler unconditionally has __STDC__ defined as 0,
without a compiler option to change it to 1.

 KB> But anyway, I suspect that we can just remove the decl entirely.
 KB> I'm doing that now.  We'll see if that causes new brokenness.

maybe we should add a check to configure:

AC_CHECK_DECLS(getopt, [], [], [[#include <unistd.h>]])

and then define the getopt prototype conditionally:

#if !HAVE_DECL_GETOPT
extern KPSEDLL int getopt ();
#endif

in both places in getopt.h ?

Best,
v.


More information about the tlbuild mailing list