y.tab.c: undefined reference to yylex

泪湿孤枕 提交于 2019-12-05 09:28:50

If you just use

flex -l calc3.l

then flex produces a scanner called lex.yy.c. Similarly, if you just use

yacc -vd calc3.y

the bison will produce files called y.tab.c and y.tab.h. And

gcc y.tab.c -lm -ll

will produce a file called a.out.

None of that is a good idea. It's far better to give the files meaningful names, based on the input filenames. All three of these tools understand a -o command-line flag which specifies the output name file.

So you could do this:

flex -l calc3.l
yacc -vd calc3.y
gcc lex.yy.c y.tab.c -lm -ll

But I'd recommend something like this:

flex -o calc3.lex.c -l calc3.l
bison -o calc3.tab.c -vd calc3.y
gcc -o calc3 calc3.lex.c calc3.tab.c -lm -ll

(When you do this, you'll need to change the #include "y.tab.h" to #include "calc3.tab.h".)

Even better if you put it in a Makefile, or at least a script file.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!