Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

parse_lex.l:79:5: error: 'yylval' undeclared (first use in this function) #22

Closed
brianjmurrell opened this issue Mar 8, 2017 · 6 comments

Comments

@brianjmurrell
Copy link
Contributor

When I try to build master on EL 7.3 I get:

  CC       parse_lex.o
parse_lex.l: In function 'yylex':
parse_lex.l:79:5: error: 'yylval' undeclared (first use in this function)
     yylval = yytext;
     ^
parse_lex.l:79:5: note: each undeclared identifier is reported only once for each function it appears in
parse_lex.l: At top level:
parse_lex.c:1743:16: warning: 'input' defined but not used [-Wunused-function]
     static int input  (void)
                ^
make[1]: *** [parse_lex.o] Error 1

Yacc is one tool I never got my head around. Any idea what might be going wrong here?

@garlick
Copy link
Member

garlick commented Mar 8, 2017

Just checked out a clean copy on RHEL 7.3 and it built OK for me (I did get the 'input' warning).

Configure says:

checking for flex... flex
checking lex output file root... lex.yy
checking lex library... -lfl
checking whether yytext is a pointer... yes
checking for bison... bison -y

make V=1 says

test -f parse_tab.c || /bin/sh ../config/ylwrap parse_tab.y y.tab.c parse_tab.c y.tab.h `echo parse_tab.c | sed -e s/cc$/hh/ -e s/cpp$/hpp/ -e s/cxx$/hxx/ -e s/c++$/h++/ -e s/c$/h/` y.output parse_tab.output -- bison -y -d 
conflicts: 7 shift/reduce
updating parse_tab.h
test -f parse_lex.c || /bin/sh ../config/ylwrap parse_lex.l lex.yy.c parse_lex.c -- flex  
depbase=`echo parse_lex.o | sed 's|[^/]*$|.deps/&|;s|\.o$||'`;\
gcc -DHAVE_CONFIG_H -I. -I../config  -I../liblsd -I../libcommon  -Wall -g -O2 -MT parse_lex.o -MD -MP -MF $depbase.Tpo -c -o parse_lex.o parse_lex.c &&\
mv -f $depbase.Tpo $depbase.Po
parse_lex.c:1743:16: warning: 'input' defined but not used [-Wunused-function]
     static int input  (void)
                ^
depbase=`echo parse_tab.o | sed 's|[^/]*$|.deps/&|;s|\.o$||'`;\
gcc -DHAVE_CONFIG_H -I. -I../config  -I../liblsd -I../libcommon  -Wall -g -O2 -MT parse_tab.o -MD -MP -MF $depbase.Tpo -c -o parse_tab.o parse_tab.c &&\
mv -f $depbase.Tpo $depbase.Po
depbase=`echo parse_util.o | sed 's|[^/]*$|.deps/&|;s|\.o$||'`;\

Maybe check that your copy starts clean (not having yacc/lex results from a build somewhere else), and if that's not it, post your output here so we can compare?

@brianjmurrell
Copy link
Contributor Author

My build is by definition "clean" as I am using rpmbuild to build it.

From my build:

checking for flex... flex
checking lex output file root... lex.yy
checking lex library... none needed
checking whether yytext is a pointer... no
checking for bison... no
checking for byacc... byacc

and make V=1 says:

Making all in powermand
make[1]: Entering directory `/topdir/BUILD/powerman-66cedb7/powermand'
...
gcc -DHAVE_CONFIG_H -I. -I../config  -I../liblsd -I../libcommon  -Wall -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches   -m64 -mtune=generic -c -o parse_lex.o parse_lex.c
parse_lex.l: In function 'yylex':
parse_lex.l:79:5: error: 'yylval' undeclared (first use in this function)
     yylval = yytext;
     ^
parse_lex.l:79:5: note: each undeclared identifier is reported only once for each function it appears in
parse_lex.l: At top level:
parse_lex.c:1743:16: warning: 'input' defined but not used [-Wunused-function]
     static int input  (void)
                ^
make[1]: *** [parse_lex.o] Error 1

Interestingly I don't have all of the:

test -f parse_tab.c || /bin/sh ../config/ylwrap parse_tab.y y.tab.c parse_tab.c y.tab.h `echo parse_tab.c | sed -e s/cc$/hh/ -e s/cpp$/hpp/ -e s/cxx$/hxx/ -e s/c++$/h++/ -e s/c$/h/` y.output parse_tab.output -- bison -y -d 
conflicts: 7 shift/reduce
updating parse_tab.h
test -f parse_lex.c || /bin/sh ../config/ylwrap parse_lex.l lex.yy.c parse_lex.c -- flex  
depbase=`echo parse_lex.o | sed 's|[^/]*$|.deps/&|;s|\.o$||'`;\

that you have. My make dist tarball does already have a parse_lex.c though. I guess make dist is creating it.

So I double-checked the build of that file by doing an rm -f powermand/parse_lex.c; make dist on the exact same machine as I am trying to build with (using rpmbuild -bb --define _sourcedir\ $PWD powerman.spec FWIW) . Still failing the same way.

@garlick
Copy link
Member

garlick commented Mar 8, 2017

yylval is defined in the parse_tab.h generated by bison. I can reproduce that error if I configure with

YACC=byacc ./configure

Installing bison might be a workaround for you, but we should get this fixed.

@garlick
Copy link
Member

garlick commented Mar 8, 2017

Looks like YACC="byacc -i" will cause a file y.tab.i to be generated that includes a def of yylval. If I configure that way then manually #include "y.tab.i" from parse_lex.l right before parse_tab.h this gets things compiled. Not sure how to make that work portably though.

Hmm, feels wrong, but this works with both bison and byacc

diff --git a/powermand/parse_lex.l b/powermand/parse_lex.l
index d68962c..87f21e7 100644
--- a/powermand/parse_lex.l
+++ b/powermand/parse_lex.l
@@ -30,6 +30,7 @@
 #endif
 /* N.B. must define YYSTYPE before including parse_tab.h or type will be int. */
 #define YYSTYPE char *
+extern YYSTYPE yylval;
 #include <string.h>
 #include <stdio.h>
 #include <stdlib.h>

@brianjmurrell
Copy link
Contributor Author

So, yeah. I installed byacc just because that's what yum search yacc returned. I am happy to install something different.

Simply installing bison, without doing anything else doesn't seem to resolve it.

@garlick
Copy link
Member

garlick commented Mar 8, 2017

make clean?

brianjmurrell added a commit to brianjmurrell/powerman that referenced this issue Mar 9, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants