How can I test a specific gcc function in configure.ac file

For example, gcc 4.7 has a new function -Wnarrowing. In configure.ac, how can I check where a function is supported by current gcc or not?
There is a file in gnulibc, but it makes no sense to me.

+4
source share
3 answers

See http://code.google.com/p/opendoom/source/browse/trunk/VisualC8/autotools/ac_c_compile_flags.m4 for an example of this type of test - it tries to compile a trivial program with the given compiler flag and adds it to CFLAGS. if it works.

0
source

, , :

, -Wnarrowing. , . .

-Wnarrowing , . , , -Wnarrowing , .

, -Werror=narrowing , . , , -Wnarrowing. , -Wnarrowing/-Werror=narrowing, " -Wnarrowing". -Wnarrowing.

, -Wnarrowing -Werror=narrowing, , -Wnarrowing , -Werror=narrowing . , .

.

+1

gcc clang -W[no-]narrowing -W[no-]error=narrowing.

-std=c++11 gcc , clang . gcc, , , clang, . Intel icc.

, ++ AC_PROG_CXX ++ 11.

ac_save_CXXFLAGS="$CXXFLAGS"
CXXFLAGS="$CXXFLAGS -Werror -Wno-error=narrowing"
AC_LANG_PUSH([C++])

AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],
  [[int i {1.0}; (void) i;]])],
  [ac_cxx_warn_narrowing=1], [ac_cxx_warn_narrowing=0])

AS_IF([test $ac_cxx_warn_narrowing -ne 0],
  [AC_MSG_RESULT(['$CXX' supports -Wnarrowing])])

AC_LANG_POP([C++])
CXXFLAGS="$ac_save_CXXFLAGS"

, : 1) -Wnarrowing , , -Werror : 2) ++ 11.

Typically, configure.acscripts and flags passed to configure should be avoided -Werror, as this breaks too many internal tests. In this context, we guarantee the absence of warnings other than narrowing, therefore (void) i;it is necessary to prevent warnings about unused variables.

+1
source

All Articles