config.h vs. -D

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

 



Hello all,

having a medium size project that i want to built with GNU autotools,
i discovered that using or not using a config.h file seems to be not
interchangeable (at least if one is doing macro expansion the way i
did - this might be understanding the expansion wrong at all ...):

I would like to have a default file location hard coded in my binary
but of course depending on the installation path.  The file will be
installed in $(datadir), so i was looking for something like

<snip sourcefile foo.c>
#ifndef MY_CONFIG_FILE
#define MY_CONFIG_FILE "my_config_file"
#endif /* !MY_CONFIG_FILE */

const char *defaultConfFile = MY_CONFIG_FILE
...
	printf("MY_CONFIG_FILE: %s\n", defaultConfFile);
...
<snip>

and

<snip configure.in>
MY_CONFIG_FILE="@datadir@/my_config_file"
AC_DEFINE_UNQUOTED([MY_CONFIG_FILE], "$MY_CONFIG_FILE",
	[default configuration file])
<snip>

which leads to

bsailer@host $ ./configure --prefix=$HOME
...
bsailer@host $ ./foo
MY_CONFIG_FILE: /home/bsailer/share/my_config_file
bsailer@host $

now i'd like to use config.h (as there will be many defines in my project),
but as soon as introducing

<snip configure.in>
AC_CONFIG_HEADERS(config.h)
</snip>

and

<snip config.h.in>
/* default configuration file */
#undef MY_CONFIG_FILE
</snip>

after configuration and build the output changes:

bsailer@host $ ./configure --prefix=$HOME
...
bsailer@host $ ./foo
MY_CONFIG_FILE: @datadir@/my_config_file
bsailer@host $

what an i doing wrong?  I'm using

automake-1.7.6-1
autoconf-2.57-3

Thanks in advance for all advices ...

Benjamin

-- 
*****************************************************************
Benjamin Sailer
eMail: Benjamin.Sailer@xxxxxxxxx
*****************************************************************
Disclaimer:  This signature has been generated automatically and
does not reflect my opinion at all.
                -- Benjamin Sailer

I'd like to meet the guy who invented beer and see what he's working on now.




[Index of Archives]     [GCC Help]     [Kernel Discussion]     [RPM Discussion]     [Red Hat Development]     [Yosemite News]     [Linux USB]     [Samba]

  Powered by Linux