Dear LazyWeb, autoconf and #define HAVE_ 0

How do I make an existing project (let’s say, MySQL) switch from generating a config.h that has #undef HAVE_FOO to one that generates #define HAVE_FOO 0 instead?

Why? Well, here’s why:

Testing for features should be done by including “config.h” and using #if HAVE_<feature>. Use of #if (rather than #ifdef) allows the gcc -Wundef flag to warn users about features which aren’t defined 1 or 0 in config.h.

4 Responses to “Dear LazyWeb, autoconf and #define HAVE_ 0”

  1. Erik says:

    To make it so, you need something like this in configure.ac:

    PKG_CHECK_MODULES(SNDFILE, sndfile >= 1.0.6, ac_cv_sndfile=1, ac_cv_sndfile=0)
    AC_DEFINE_UNQUOTED([HAVE_SNDFILE],$ac_cv_sndfile,[Set to 1 if you have libsndfile.])

    HTH :-)

  2. Erik says:

    Stewart, was that of any use to you?

Leave a Reply