[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: getopt.h broken on FreeBSD
From: |
Jim Meyering |
Subject: |
Re: getopt.h broken on FreeBSD |
Date: |
Mon, 19 Oct 2009 13:07:17 +0200 |
Sergey Poznyakoff wrote:
> We've got one more problem with getopt.h. It manifests
> itself when compiling lex-generated parsers on FreeBSD.
> What happens is the following: the system getopt.h defines
> getopt_long, struct option and the accompanying stuff,
> but does not define __need_getopt. Consequently, gnulib's
> getopt.h includes it and attempts to redefine struct option
> afterwards. This works so far as config.h is included before
> getopt.h or unistd.h, but fails if it was not:
>
> In file included from ../../gnu/unistd.h:56,
> from grecs-lex.c:12:
> ../../gnu/getopt.h:184: error: redefinition of 'struct option'
>
> The error is triggered by the fact that the default flex
> skeleton begins with
>
> #include <stdio.h>
> #include <unistd.h>
>
> and gives no way to insert anything before this.
>
> I see the following possible solutions:
>
> 1. Define __GETOPT_PREFIX directly in getopt.in.h, instead of config.h.
>
> The comment at line 40 says that 'Standalone applications should
> #define __GETOPT_PREFIX', so its seems a natural solution, given
> that only standalone applications use gnulib.
Hi Sergey,
How about just using flex's %top directive?
I use this in GNU cppi.l:
%top{
/* config.h must precede flex's inclusion of <stdio.h>
in order for its _GNU_SOURCE definition to take effect. */
#include "config.h"
}