本文介绍了找到GCC版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用autoconf / automake如何在系统上找到GCC版本?

Using autoconf/automake how does one find the GCC version on the system?

要获得安装的python版本,可以使用AM_PATH_PYTHON,然后使用PYTHON_VERSION变量将可用。是否有类似的GCC版本?

To get the python version installed you'd use AM_PATH_PYTHON, and then the PYTHON_VERSION variable would be available. Is there something similar for the GCC version?

(另外,是否有可能获得gcc的主要,次要和补丁级别?)

(Also, is it possible to get the major, minor and patch level of gcc?)

推荐答案

快速搜索显示宏应该给你 GCC_VERSION 变量。

A quick search reveals the ax_gcc_version macro which should give you the GCC_VERSION variable.

不幸的是,取决于 AX_GCC_OPTION ,最近 AX _ * _ CHECK_FLAG

Unfortunately, that macro depends on AX_GCC_OPTION which has recently been deprecated in favour of of AX_*_CHECK_FLAG.

这份为 ax_gcc_version 提供了一个补丁,它等于:

This mailing list post suggests a patch for ax_gcc_version which amounts to:

AC_DEFUN([AX_GCC_VERSION], [
  GCC_VERSION=""
  AX_CHECK_COMPILE_FLAG([-dumpversion],
     [ax_gcc_version_option=yes],
     [ax_gcc_version_option=no])

  AS_IF([test "x$GCC" = "xyes"],[
    AS_IF([test "x$ax_gcc_version_option" != "xno"],[
      AC_CACHE_CHECK([gcc version],[ax_cv_gcc_version],[
        ax_cv_gcc_version="`$CC -dumpversion`"
        AS_IF([test "x$ax_cv_gcc_version" = "x"],[
          ax_cv_gcc_version=""
        ])
      ])
      GCC_VERSION=$ax_cv_gcc_version
    ])
  ])
  AC_SUBST([GCC_VERSION])
])

我没有测试过这个,但看起来很合理。




I have not tested this, but it looks sensible.

一旦你拥有版本字符串位于 GCC_VERSION 中,您可以手动拆分字符串以获取主版本,次版本和补丁版本。这是一个简单的解决方案:

Once you have the version string in GCC_VERSION, you can manually split the string to get the major, minor and patch versions. Here's a simple-minded solution:

GCC_VERSION_MAJOR=$(echo $GCC_VERSION | cut -d'.' -f1)
GCC_VERSION_MINOR=$(echo $GCC_VERSION | cut -d'.' -f2)
GCC_VERSION_PATCH=$(echo $GCC_VERSION | cut -d'.' -f3)

这篇关于找到GCC版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-22 12:26