在 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/