Why does autoconf erroneously find a function whic

2020-04-23 07:46发布

问题:

On a Linux system I configured a software package (llvm) and autoconf finds the arc4random function. Here an extraction of the output during configuration:

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

Configuring goes fine. Later, when building the package I get an error about an undeclared specifier arc4random:

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

Here the referred location:

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

It's properly guarded, here the configure.ac piece:

AC_CHECK_FUNCS([strerror strerror_r setenv arc4random ])

Seems all fine. I am wondering why the configure process detected the function to be available.

autoconf (GNU Autoconf) 2.63

Here the extract from 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

回答1:

According to arc4random(3), to use this function, you should include <bsd/stdlib.h> in your code and link it with -lbsd.

What this AC_CHECK_FUNCS([... arc4random ]) does is to make sure arc4random exists in your system, then define the macro named HAVE_ARC4RANDOM, but it cannot guarantee your code is using it correctly.