gcc - 如何声明 __sync_fetch_and_add?

标签 gcc synchronization autoconf

我正在编写一个可以非常使用 __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

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

谢谢。

最佳答案

AC_CHECK_FUNCS在这种情况下不可用,因为重新声明 autoconf 所做的函数(char functionthatiwant()/conftest.c 中的 config.log )会不利地覆盖内置函数。您将需要类似以下内容。

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])]
)

关于gcc - 如何声明 __sync_fetch_and_add?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9407380/

相关文章:

installation - autotools 仅在较新时安装 header

c++ - 如何使用#pragma 在 G++ 中启用优化

c - 包装一个函数

GNU 自动工具 : How do you include source files in the 'make dist' tarball that are above the root source directory?

c# - 为什么枚举集合会抛出异常但循环遍历其项目却不会

c++ - 由于使用事件而产生的开销

autotools - 当我的包仅用 C 构建时,如何告诉 autoconf 不要探测 fortran、C++ 等?

c - 排除 GNU 作为 (GAS) 标准启动代码

c - 当我尝试从 C 程序调用已编译的 NASM 函数时出现 undefined reference 错误

java - Java中同步两个方法