2011-05-13 40 views

回答

3

我不認爲這是一個標準的宏,但是這裏是你應該能夠根據需要擴展以支持其他編譯器的東西,例如, __hidden對於Sun編譯:

AC_CACHE_CHECK([for __attribute__((visibility("hidden")))], 
    ac_cv_hidden_visibility_attribute, [ 
    echo 'int __attribute__ ((visibility ("hidden"))) foo (void) { return 1; }' > conftest.c 
    ac_cv_hidden_visibility_attribute=no 
    if AC_TRY_COMMAND(${CC-cc} -Werror -S conftest.c -o conftest.s 1>&AS_MESSAGE_LOG_FD); 
    then 
     if grep '\.hidden.*foo' conftest.s >/dev/null; 
     then 
      ac_cv_hidden_visibility_attribute=yes 
     fi 
    fi 
    rm -f conftest.* 
    ]) 
if test $ac_cv_hidden_visibility_attribute = yes; 
then 
    AC_DEFINE(HAVE_HIDDEN_VISIBILITY_ATTRIBUTE, 1, 
      [Define if __attribute__((visibility("hidden"))) is supported.]) 
fi 

產生的config.h

/* Define if __attribute__((visibility("hidden"))) is supported. */ 
#define HAVE_HIDDEN_VISIBILITY_ATTRIBUTE 1 
0

你可以嘗試使用<sys/cdefs.h>與宏觀__hiden