Default compiler flags with Autotools

According to autoconf manual (about AC_PROG_CC):

If using the GNU C compiler, set shell variable GCC to ‘yes’. If
output variable CFLAGS was not already set, set it to -g -O2 for the
GNU C compiler (-O2 on systems where GCC does not accept -g), or -g
for other compilers. If your package does not like this default, then
it is acceptable to insert the line

: ${CFLAGS=""}

after AC_INIT and before AC_PROG_CC to select an empty default
instead.

Similarly, according to autoconf manual (about AC_PROG_CXX):

If using the GNU C++ compiler, set shell variable GXX to ‘yes’. If
output variable CXXFLAGS was not already set, set it to -g -O2 for the
GNU C++ compiler (-O2 on systems where G++ does not accept -g), or -g
for other compilers. If your package does not like this default, then
it is acceptable to insert the line

: ${CXXFLAGS=""}

after AC_INIT and before AC_PROG_CXX to select an empty default
instead.

Leave a Comment