On Wed, Dec 20, 2006 at 09:09:33AM -0800, Ian Lance Taylor wrote: > Bob Rossi <bob_rossi@xxxxxxx> writes: > > > What's the best way to get the gcc version number from an autotools > > project? I could start gcc and parse the output. Could I write a small > > program that checks some #define that has gcc's version number? > > You can check __GNUC__, __GNUC_MINOR__, and __GNUC_PATCHLEVEL__. Is > that the sort of thing you are looking for? > > > If so, how far back does that work for? > > __GNUC__ and __GNUC_MINOR__ have been around for a long time, > certainly since before gcc 3.0 (and, although I didn't check, probably > before gcc 2.0). I believe that __GNUC_PATCHLEVEL__ was added in gcc > 3.0. Thanks, here is what I did, in case others find it useful. Bob Rossi AC_MSG_CHECKING([for $CC version]) AC_RUN_IFELSE([AC_LANG_PROGRAM( [[#include <stdio.h>]], [[ FILE *fp; fp = fopen("conftest.cc", "w"); if (fp == 0) return(1); fprintf(fp, "ac_cv_cc_major_version=%d;ac_cv_cc_minor_version=%d;ac_cv_cc_patch_version=%d", __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__); fclose(fp); ]])], [eval `cat conftest.cc`], [ac_cv_cc_major_version=no]) if test "$ac_cv_cc_major_version" = "no"; then AC_MSG_RESULT([no]) AC_MSG_FAILURE(Requires that $CC is usable],[1]) else ac_cv_cc_version="$ac_cv_cc_major_version.$ac_cv_cc_minor_version.$ac_cv_cc_patch_version" AC_MSG_RESULT([$ac_cv_cc_version]) fi;