【问题标题】:How do I declare __sync_fetch_and_add?如何声明 __sync_fetch_and_add?
【发布时间】:2012-03-13 12:34:06
【问题描述】:

我正在编写一个可以大量使用__sync_fetch_and_add 的程序。不幸的是,我的 autoconf 脚本通过这个相当简单的测试来搜索它:

AC_CHECK_FUNCS([__sync_fetch_and_add])

产生这个错误:

Wsuggest-attribute=noreturnconftest.c:56:1: warning: function declaration isn't a prototype [-Wstrict-prototypes]
conftest.c:56:6: warning: conflicting types for built-in function '__sync_fetch_and_add' [enabled by default]
conftest.c:65:1: warning: function declaration isn't a prototype [-Wstrict-prototypes]
/tmp/ccqPsZz4.o: In function `main':
/home/simsong/domex/src/bulk_extractor/tags/1.2.x/conftest.c:67: undefined reference to `__sync_fetch_and_add'
collect2: ld returned 1 exit status

这太烦人了,因为我想使用该功能,但是某些平台上的某些人告诉我它无法正确编译。我想要一个原型,但似乎没有。

谢谢。

【问题讨论】:

    标签: gcc synchronization autoconf


    【解决方案1】:

    AC_CHECK_FUNCS 在这种情况下不可用,因为重新声明函数——autoconf 所做的(conftest.c/config.log 中的char functionthatiwant())——将有害地覆盖内置函数。你需要类似下面的东西。

    AC_MSG_CHECKING([for __sync_fetch_and_add])
    AC_LINK_IFELSE(
       [AC_LANG_SOURCE([
        int main(void) { return __sync_fetch_and_add((int *)0, 0); }
       ])],
       [AC_MSG_RESULT([yes])],
       [AC_MSG_RESULT([no])]
    )
    

    【讨论】:

      猜你喜欢
      • 2021-08-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多