autoconf
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: checking if CC supports weak symbols


From: Ralf Corsepius
Subject: Re: checking if CC supports weak symbols
Date: 24 Jan 2003 03:56:26 +0100

On Fri, 2003-01-24 at 00:53, Peter Eisentraut wrote:
> Ralf Corsepius writes:
> 
> > More precisely, I am trying to detect whether a c-compiler supports
> > gcc's "function __attribute__((weak))" syntax or not.
> 
> Is there any reason to think that compilers other than GCC support this
> syntax?
Well, that's one of the aspects I wanted to find out. I suspect this
particular syntax to be specific to gcc, but I would expect other
compilers to support "weak symbols", too. (How about Intel's icc?)


For the moment, this is what I am using:

AC_CACHE_CHECK([whether $CC supports function __attribute__((weak))],
[ac_cv_gcc_attribute_weak],[
AS_IF([test $GCC = yes],[
  save_CFLAGS=$CFLAGS
  CFLAGS=-Werror
  AC_COMPILE_IFELSE([
    AC_LANG_PROGRAM(
    [void myfunc(char c) __attribute__ ((weak));
     void myfunc(char c) {}],
    [])],
    [ac_cv_gcc_attribute_weak=yes],
    [ac_cv_gcc_attribute_weak=no])
  CFLAGS=$save_CFLAGS
],[
  ac_cv_gcc_attribute_weak=no])
])

However, there are several aspects I don't like about this check:
* It is strictly tied to gcc.
* It evaluates a warning from gcc(gcc issues warnings if it doesn't
support this syntax)

May-be this less restrictive variant would be better:

AC_CACHE_CHECK([whether $CC accepts function __attribute__((weak))],
[ac_cv_cc_attribute_weak],[
  AS_IF([test $GCC = yes],[
    save_CFLAGS=$CFLAGS
    CFLAGS=-Werror])

  AC_COMPILE_IFELSE([
    AC_LANG_PROGRAM(
    [void myfunc(char c) __attribute__ ((weak));
     void myfunc(char c) {}],
    [])],
    [ac_cv_cc_attribute_weak=yes],
    [ac_cv_cc_attribute_weak=no])

  AS_IF([test $GCC = yes],[
    CFLAGS=$save_CFLAGS])
])

Actually, I would prefer a check to find out whether a
compiler/toolchain supports weak symbols and if necessary, to let it
find the syntax this compiler requires. (IIRC, some older gcc's used
#pragma weak)

Ralf






reply via email to

[Prev in Thread] Current Thread [Next in Thread]