【问题标题】:Why does autoconf erroneously find a function which isn't available later?为什么 autoconf 会错误地找到以后不可用的功能?
【发布时间】:2014-04-06 15:56:49
【问题描述】:

在 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

【问题讨论】:

    标签: linux autotools autoconf


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-27
      • 1970-01-01
      • 2023-01-26
      • 1970-01-01
      相关资源
      最近更新 更多