问题
Using autoconf/automake how does one find the GCC version on the system?
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?
(Also, is it possible to get the major, minor and patch level of gcc?)
回答1:
A quick search reveals the ax_gcc_version macro which should give you the GCC_VERSION
variable.
Unfortunately, that macro depends on AX_GCC_OPTION
which has recently been deprecated in favour of of AX_*_CHECK_FLAG
.
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.
(Also, is it possible to get the major, minor and patch level of gcc?)
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)
来源:https://stackoverflow.com/questions/7067385/find-the-gcc-version