在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

配置正常。稍后,在构建包时,我得到一个关于未声明的说明符的错误:
[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

它有很好的保护,这里是arc4random部分:
AC_CHECK_FUNCS([strerror strerror_r setenv arc4random ])

看起来一切都很好。我想知道为什么配置过程检测到功能可用。
autoconf(GNU autoconf)2.63
这里是configure.ac的摘录:
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,然后定义名为“cc>”的宏,但不能保证代码正确使用。

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

10-12 21:43