Automake: AM_CFLAGS has no effect Automake: AM_CFLAGS has no effect unix unix

Automake: AM_CFLAGS has no effect


  1. It looks like you're compiling C++, in which case the variable to use is AM_CXXFLAGS.
  2. Setting AM_CXXFLAGS should be in the Makefile.am that declares things you're actually compiling (i.e., bin_PROGRAMS, lib_LTLIBRARIES, ...).
  3. If you're repeating yourself, don't forget automake supports an include statement.
  4. Recursive make considered harmful. Modern automake supports subdir-objects. If one Makefile.am gets out of hand, use include statements.
  5. The modern way to turn on libtool is LT_INIT, not AC_PROG_LIBTOOL.
  6. AC_LANG(C++) doesn't do anything at point of configure.ac. It sets the language to use when running configure tests. Besides, AC_LANG_PUSH and AC_LANG_POP are smarter ways of doing that.
  7. Why are you assigning to ACLOCAL_AMFLAGS like that?


I tried adding AM_CFLAGS to the parent Makefile.am as suggested, which didn't work. When I added it to the relevant Makefile.am, it ended introducing two conflicting -g options as shown below:

libtool: link: gcc -std=gnu99 -g -O0 -g -O2 -Wl -pthread ...

The correct way to disable optimization is to add CFLAGS = -g -O0 to the Makefile.am where it's needed. Try deleting Makefile.in and Makefile (no extension) if the change doesn't take effect for some reason.

Here's the correct linker directive:

libtool: link: gcc -std=gnu99 -g -O0 -Wl -pthread ...