autoconf
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Using AC_DEFINE with AC_ARG_ENABLE (or AC_ARG_WITH)


From: Chris Packham
Subject: Re: Using AC_DEFINE with AC_ARG_ENABLE (or AC_ARG_WITH)
Date: Thu, 15 Aug 2019 20:58:00 +0000

Hi Nick, Mauro,

On Thu, 2019-08-15 at 09:56 -0400, Nick Bowler wrote:
> Hi Chris,
> 
> On 8/15/19, Chris Packham <address@hidden> wrote:
> > 
> > I'm trying to get a value provided on the ./configure invocation
> > through to C code so it can be used. I'm trying to do this with
> > AC_DEFINE but maybe this is a job for something else.
> [...]
> > 
> > AC_DEFINE([ENTITY],[${enable_entity}],[Entity])
> [...]
> > 
> > In file included from <command-line>:0:0:
> > test.c: In function ‘main’:
> > ./config.h:5:16: error: ‘$’ undeclared (first use in this function)
> >  #define ENTITY ${enable_entity}
> > 
> > Which is a bit too literal. I suspect I'm missing something (like
> > AC_SUBST). But I can't for all the searching figure out how to get
> > a
> > value from the ./configure invocation through to the end program.
> You must use AC_DEFINE_UNQUOTED[1] if you want shell expansion to
> be performed on the value.
> 
> [1] https://www.gnu.org/savannah-checkouts/gnu/autoconf/manual/autoco
> nf-2.69/autoconf.html#Defining-Symbols
> 
> Hope that helps,
>   Nick

Yes thanks AC_DEFINE_UNQUOTED did the trick.

For mailing list archive readers I had a typo in my AC_ARG_ENABLE as
well. This is the delta to my original post that now works as expected

diff --git a/configure.ac b/configure.ac
index 259027e..ed6830a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -9,7 +9,7 @@ AC_CONFIG_FILES([Makefile])
 AC_ARG_ENABLE([entity],
   [AS_HELP_STRING([--enable-entity],
     [Set entity @<:@default=World@:>@])],
   [],
-  [enable_enity=World])
+  [enable_entity=World])
 
-AC_DEFINE([ENTITY],[${enable_entity}],[Entity])
+AC_DEFINE_UNQUOTED([ENTITY],["${enable_entity}"],[Entity])
 AC_OUTPUT

reply via email to

[Prev in Thread] Current Thread [Next in Thread]