views:

33

answers:

2

I am using GNU autotools for my project. The configure.ac script has the following snippet.

AC_ARG_WITH(chkhere,
 AC_HELP_STRING([--without-chkhere], [do not compile]),
 [ac_cv_chkhere=$withval], [ac_cv_chkhere=yes])

# Check if chkhere is available
if test "x$ac_cv_chkhere" = "xyes"
then
 AC_DEFINE(HAVE_CHECKED)
 echo "chkhere: enabled"
else
  echo "chkhere: DISABLED"
fi

And I am checking for the variable HAVE_CHECKED in the C++ code. This works for --without-chkhere option.

When I am giving ./configure --with-chkhere, it shows the message "chkhere: enabled" as required, but HAVE_CHECKED turns up undefined inside the C++ code.

Please suggest where I am going wrong, or if I can test this differently? Thanks.

P.S.: I am following this sequence of commands: automake; libtoolize; aclocal -I m4; autoconf;

+1  A: 

Are you making sure to #include <config.h>? That's where HAVE_CHECKED will be defined.

EDIT

My version of autoheader complains and fails when you don't use the full form of AC_DEFINE:

AC_DEFINE([HAVE_CHECKED], [1], [some description])

So your config.h.in wouldn't be getting updated even if you did call autoheader.

ptomato
Yes, I have. And I verified that it is not getting defined in config.h either.
SkypeMeSM
+1  A: 

If you didn't call autoheader then config.h.in may be out of date and may not mention HAVE_CHECKED. I suggest you just ditch your sequence of commands and use autoreconf instead, it will run what you need.

adl