gcc unrecognized command line options '-V' and '-qversion' with autoconf

When compiling with gcc 4.7.2 and autoconf 2.69, I am routinely getting results such as these in configure.log. Example:

configure:3091: $? = 0 
configure:3080: gcc -V >&5 
gcc: error: unrecognized command line option '-V' 
gcc: fatal error: no input files compilation terminated. 
configure:3091: $? = 1 
configure:3080: gcc -qversion >&5 
gcc: error: unrecognized command line option '-qversion' 
gcc: fatal error: no input files compilation terminated. 
configure:3091: $? = 1 
configure:3111: checking whether the C compiler works 
configure:3133: gcc -march=x86-64 -mtune=generic -Os -pipe -Wl,-O1 conftest.c >&5
configure:3137: $? = 0 
configure:3185: result: yes

The compilation proceeds successfully, but I am wondering why autoconf is testing for command lines that gcc does not support. Is this for other compilers?


Solution 1:

Citing this:

  • https://serverfault.com/questions/580489/configure-error-c-compiler-cannot-create-executables-while-build-ruby-from-sou

gcc -V is a way of selecting a specific gcc version when you have more than one, that's a decoy here though: configure is iterating through a set of options (--version -v -V etc.) to make sure it can log the version of the C compiler, be it gcc or something else.

Citing this:

  • http://www.linuxquestions.org/questions/linux-newbie-8/slackware-configure-error-4175507097/#post5182892

gcc used to have a -V option for version reports. It now uses -v, and provides the configuration options used when the compiler was built.

You package is a bit dated and doesn't reflect that fact.

BTW, the -qversion option was merged into the -v...

Citing this:

  • https://stackoverflow.com/questions/20678016/autoconf-complains-c-compiler-cannot-create-executables-on-linux-mint

On some versions of gcc, the -V option tells it to use a specified version of the compiler -- but it requires an argument. It's documented here. The option appears to have been removed some time between 4.5.4 and 4.6.4.

which references this:

  • https://gcc.gnu.org/onlinedocs/gcc-4.1.2/gcc/Target-Options.html

Solution 2:

Modern autoconf version 2.69 could be used with the following extended compiler information extraction method:

# Provide some information about the compiler.
$as_echo "$as_me:${as_lineno-$LINENO}: checking for C compiler version" >&5
set X $ac_compile
ac_compiler=$2
for ac_option in --version -v -V -qversion; do
  { { ac_try="$ac_compiler $ac_option >&5"
case "(($ac_try" in
  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
  *) ac_try_echo=$ac_try;;
esac
eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
$as_echo "$ac_try_echo"; } >&5
  (eval "$ac_compiler $ac_option >&5") 2>conftest.err
  ac_status=$?
  if test -s conftest.err; then
    sed '10a\
... rest of stderr output deleted ...
         10q' conftest.err >conftest.er1
    cat conftest.er1 >&5
    rm -f conftest.er1 conftest.err
  fi
  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
  if test $ac_status = 0; then break; fi}
done

It's already adapted to try modern as well as legacy version extraction flags.  The fix is at the very last line, allowing to skip testing after 1st success.