3

The following is inside GNU m4 sources in a file called lib/verror.h :

/* Declaration for va_list error-reporting function
   Copyright (C) 2006-2007, 2009-2011 Free Software Foundation, Inc.

   This program is free software: you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 3 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */

#ifndef _VERROR_H
#define _VERROR_H 1

#include "error.h"
#include <stdarg.h>

#ifdef __cplusplus
extern "C" {
#endif

/* Print a message with `vfprintf (stderr, FORMAT, ARGS)';
   if ERRNUM is nonzero, follow it with ": " and strerror (ERRNUM).
   If STATUS is nonzero, terminate the program with `exit (STATUS)'.
   Use the globals error_print_progname and error_message_count similarly
   to error().  */

extern void verror (int __status, int __errnum, const char *__format,
                    va_list __args)
     __attribute__ ((__format__ (__printf__, 3, 0)));

/* Print a message with `vfprintf (stderr, FORMAT, ARGS)';
   if ERRNUM is nonzero, follow it with ": " and strerror (ERRNUM).
   If STATUS is nonzero, terminate the program with `exit (STATUS)'.
   If FNAME is not NULL, prepend the message with `FNAME:LINENO:'.
   Use the globals error_print_progname, error_message_count, and
   error_one_per_line similarly to error_at_line().  */

extern void verror_at_line (int __status, int __errnum, const char *__fname,
                            unsigned int __lineno, const char *__format,
                            va_list __args)
     __attribute__ ((__format__ (__printf__, 5, 0)));

#ifdef __cplusplus
}
#endif

#endif /* verror.h */

My compiler blows up all over that strange thing called "attribute" and I looked in the K&R C for it but can not find it.

Looks to be a strictly GNUism GCC thing and not C at all.

So the question is how to remove this junk to make the code able to be compiled by an old C compiler on an old Sun server? The very same compiler can build GNU make just fine as well as libiconv and gNU gettext but the latest GNU m4 looks to be non-portable.

The error that I see is :

/opt/SUNWspro/bin/cc  -I.   -D_REENTRANT -I/usr/local/include  -dy -xmemalign=8s -errfmt=error -erroff=%none -errshort=full -errwarn=%none -fns=no -ftrap=%none -xarch=v9 -xcode=pic32 -g -i -mc -Qy -v -Wl,-R/usr/local/lib -Xa -xstrconst -xtemp=/var/tmp -xunroll=1 -D_POSIX_PTHREAD_SEMANTICS -D_LARGEFILE64_SOURCE -D_TS_ERRNO -c verror.c
"verror.h", line 35: error: syntax error before or at: __attribute__
"verror.h", line 35: warning: old-style declaration or incorrect type for: __attribute__
"verror.h", line 35: warning: syntax error:  empty declaration
"verror.h", line 47: error: syntax error before or at: __attribute__
"verror.h", line 47: warning: old-style declaration or incorrect type for: __attribute__
"verror.h", line 47: error: identifier redefined: __attribute__
        current : function() returning int
        previous: function() returning int : "verror.h", line 35
"verror.h", line 47: warning: syntax error:  empty declaration
"verror.c", line 44: error: identifier redefined: verror
        current : function(int, int, pointer to const char, pointer to void) returning void
        previous: function(int, int, pointer to const char, pointer to void) returning void : "verror.h", line 33
"verror.c", line 57: error: identifier redefined: verror_at_line
        current : function(int, int, pointer to const char, unsigned int, pointer to const char, pointer to void) returning void
        previous: function(int, int, pointer to const char, unsigned int, pointer to const char, pointer to void) returning void : "verror.h", line 44
cc: acomp failed for verror.c
gmake[3]: *** [verror.o] Error 2
gmake[3]: Leaving directory `/usr/local/build/m4-1.4.16_SunOS5.8_sparcv9.001/lib'
gmake[2]: *** [all] Error 2
gmake[2]: Leaving directory `/usr/local/build/m4-1.4.16_SunOS5.8_sparcv9.001/lib'
gmake[1]: *** [all-recursive] Error 1
gmake[1]: Leaving directory `/usr/local/build/m4-1.4.16_SunOS5.8_sparcv9.001'
gmake: *** [all] Error 2

pretty nasty looking stuff that.

4

1 回答 1

2

__attribute__是一个 GCC 扩展,它也被 clang 和其他编译器借用。如果您的编译器不支持使用此语法的属性,您可以通过在使用任何属性之前定义此宏来消除错误:

#define __attribute__(x)

请记住,尽管删除属性可能会影响程序的行为。

于 2013-07-15T23:53:01.217 回答