[GRASS-dev] compilation issues with lex

Markus Neteler neteler at itc.it
Thu Aug 17 04:52:58 EDT 2006


On Thu, Aug 17, 2006 at 02:31:51AM +0100, Glynn Clements wrote:
> 
> Markus Neteler wrote:
> 
> > I have started to compile the well known software on
> > the new geodata blade of OSGeo nad encountered a few
> > problems:
> > 
> > cd lib/db/sqlp
> > make
> > gcc -I/mnt/home/neteler/software/grass6_cvs/dist.i686-pc-linux-gnu/include  -g -Wall -pedantic -Werror-implicit-function-declaration -fno-common    -fPIC    -DPACKAGE=\""grasslibs"\"     -DPACKAGE=\""grasslibs"\"  -I/mnt/home/neteler/software/grass6_cvs/dist.i686-pc-linux-gnu/include \
> >         -o OBJ.i686-pc-linux-gnu/lex.yy.o -c lex.yy.c
> > lex.l: In function 'yylex':
> > lex.l:76: error: implicit declaration of function 'strdup'
> 
> > cd raster/r.mapcalc
> > [neteler at xblade11-2 r.mapcalc]$ make
> > gcc -I/mnt/home/neteler/software/grass6_cvs/dist.i686-pc-linux-gnu/include  -g -Wall -pedantic -Werror-implicit-function-declaration -fno-common        -DPACKAGE=\""grassmods"\"  -I/mnt/home/neteler/software/grass6_cvs/dist.i686-pc-linux-gnu/include \
> >         -o OBJ.i686-pc-linux-gnu/lex.yy.o -c lex.yy.c
> > mapcalc.l: In function 'yylex':
> > mapcalc.l:134: error: implicit declaration of function 'strdup'
> 
> strdup() is defined in <string.h>, but it isn't ANSI and you're using
> -pedantic.

The problem remains when I don't use -pedantic.

I assume that -Werror-implicit-function-declaration is the problem
now:

MYCFLAGS="-g -Wall -Werror-implicit-function-declaration -fno-common"
MYCXXFLAGS="-g -Wall"

>r GRASS relies upon various POSIX functions; if you use -ansi or
> -pedantic, you also need -D_POSIX_SOURCE (you may require some others,
> e.g. _SVID_SOURCE and/or _BSD_SOURCE; ideally, those two shouldn't be
> necessary, but we can't do without _POSIX_SOURCE).

OK - interestingly these flags work well on RHEL4 and Mandriva2006
(I am using them for 1-2 years now). Maybe it only depends on
the version of gcc.
 
> For r.mapcalc, we could get around this specific issue by using
> G_store() instead. lib/db/sqlp doesn't currently use libgis, so using
> G_store() would add a new dependency.
> 
> However, there may be other non-ANSI functions which are similarly
> affected. When -ansi or -pedantic are used, ANSI headers such as
> <string.h> don't declare any non-ANSI functions unless specifically
> enabled using the appropriate macro from <features.h>.
> 
> > Help appreciated since I am not familiar with lex.
> 
> This isn't specifically a lex issue; the use of strdup() is in C code
> which lex copies verbatim to the output file (lex.yy.c).

Of course, when I reduce to
MYCFLAGS="-g -Wall"

it compiles.

Markus




More information about the grass-dev mailing list