Uli*_*ter 5 c autotools compiler-warnings
对于基于autotools的C项目,我想从编译器中获得更多警告(例如至少在CFLAGS中使用-Wall).在不破坏任何内容的情况下启用编译器标志的首选方法是什么?是否有m4宏来测试编译器是否理解给定的编译器标志?有了这样一个宏,我能做到
TEST_AND_USE(-Wall -Wextra <other flags>)
Run Code Online (Sandbox Code Playgroud)
谢谢
caf*_*caf 10
你可以使用AC_TRY_COMPILE:
AC_MSG_CHECKING(whether compiler understands -Wall)
old_CFLAGS="$CFLAGS"
CFLAGS="$CFLAGS -Wall"
AC_TRY_COMPILE([],[],
AC_MSG_RESULT(yes),
AC_MSG_RESULT(no)
CFLAGS="$old_CFLAGS")
Run Code Online (Sandbox Code Playgroud)
2015年新增:AC_TRY_COMPILE现已弃用,您应该使用AC_COMPILE_IFELSE:
AC_MSG_CHECKING(whether compiler understands -Wall)
old_CFLAGS="$CFLAGS"
CFLAGS="$CFLAGS -Wall"
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],[])],
AC_MSG_RESULT(yes),
AC_MSG_RESULT(no)
CFLAGS="$old_CFLAGS")
Run Code Online (Sandbox Code Playgroud)
根本不用改变它configure.ac.只需打电话./configure给CFLAGS你关心:
./configure CFLAGS='-Wall -Wextra -O2 -g'
Run Code Online (Sandbox Code Playgroud)