autoconf
[Top][All Lists]
Advanced

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

RE: multiple inclusion guard for config.h


From: David Fang
Subject: RE: multiple inclusion guard for config.h
Date: Mon, 22 Jan 2007 00:22:20 -0500 (EST)

> On Saturday, January 20, 2007 @ 5:50p, Ed Hartnett wrote:
>
> > David Byron wrote:
> >
> > > Any suggestions how?  I've seen people write scripts to
> > > modify/rename config.h but that seems overkill in this
> > > case.
> >
> > How about something like:
> >
> > #ifndef MY_CONFIG_INCLUDED
> > #include <../my/config.h>
> > #define MY_CONFIG_INCLUDED
> > #endif
>
> I was hoping for something where each include could just do the normal
> thing:
>
> #ifdef HAVE_CONFIG_H
> #include <config.h>
> #endif
>
> I ended up with:
>
> AH_TOP([#ifndef INCLUDED_CONFIG_H
> #define INCLUDED_CONFIG_H])
>
> AC_CONFIG_HEADERS([config.h],[echo "#endif /* INCLUDED_CONFIG_H */" >>
> config.h])
>
> Yes, if this preprocessor symbol shows up in another include file, I'm
> screwed.  In my case that doesn't happen but I suppose some convention of
> using the package name would be safer.


What I always do to keep my config headers straight is generate
non-default config.h files, e.g.

AC_CONFIG_HEADERS([src/__config__.h])



And then I provide another header (distributed), say "src/config.h" that
adds the inclusion protection with its a unique macro.


// "src/config.h"
#ifndef __MYPACKAGE_PART1_CONFIG_H__
#define __MYPACKAGE_PART1_CONFIG_H__

// include the configure-generated header
#include "__config__.h"
// or however it is referenced...

#endif

Then the rest of my sources freely reference the "src/config.h" I
provided.


Fang






reply via email to

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