linux - 为什么 autoconf 会错误地找到一个以后不可用的功能?

标签 linux autotools autoconf

在 Linux 系统上,我配置了一个软件包 (llvm),autoconf 找到了 arc4random 函数。这里是配置期间输出的提取:

checking for strerror... yes
checking for strerror_r... yes
checking for setenv... yes
checking for arc4random... yes
checking for strtoll... yes
checking for strtoq... yes
checking for sysconf... yes

配置正常。后来,在构建包时,我收到有关未声明的说明符 arc4random 的错误:

[removed]/lib/Support/Unix/Process.inc:368:10: error: use of undeclared identifier
      'arc4random'
  return arc4random();
         ^

这里是引用的位置:

367 #if defined(HAVE_ARC4RANDOM)
368   return arc4random();
369 #else
370   static int x = (::srand(GetRandomNumberSeed()), 0);
371   (void)x;
372   return ::rand();
373 #endif

它受到了适当的保护,这里是 configure.ac 部分:

AC_CHECK_FUNCS([strerror strerror_r setenv arc4random ])

看起来一切都很好。我想知道为什么配置过程检测到该功能可用。

autoconf(GNU Autoconf)2.63

这里是 config.log 的摘录:

configure --prefix=[removed] --host=powerpc64-bgq-linux --disable-terminfo --disable-zlib --enable-targets=powerpc CXX=bgclang++ CXXFLAGS=-O3 -fPIC CC=bgclang CFLAGS=-O3 -fPIC LDFLAGS=-shared

最佳答案

根据 arc4random(3) , 要使用此功能,您应该包括 <bsd/stdlib.h>在您的代码中并将其链接到 -lbsd .

这是什么AC_CHECK_FUNCS([... arc4random ])做的是确保arc4random存在于您的系统中,然后定义名为 HAVE_ARC4RANDOM 的宏,但它不能保证您的代码正确使用它。

关于linux - 为什么 autoconf 会错误地找到一个以后不可用的功能?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22183412/

相关文章:

c - sleep() 会干扰 scanf() 吗?

cygwin - 有条件地禁用共享库构建

c++ - 使用 autoconf 从二进制文件生成对象 (.o) 的自定义命令

linux - 如何每 4 小时 48 分钟安排一次 cron 作业?

python - 为什么我的 Python 代码在从另一个文件调用时添加随机单引号?

c++ - psmouse 驱动反鼠标

makefile - automake:修改隐式 make 规则以包含额外的标志

c - 当尝试为 OS X 10.6 (Snow Leopard) 配置 pcb-2011-018 时,配置报告找不到 openGL 库?

c++ - 在 autotools 项目中添加 C++ 支持?

c++ - autoconf 项目的哪些文件要放入 .gitignore?