无法编译lex的输出 [英] Unable to compile output of lex

查看:667
本文介绍了无法编译lex的输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试编译这个普通的lex程序的输出时:

 #lex.l 
integer printf (found keyword INT);

使用:

  $ gcc lex.yy.c 

我得到:

 未定义的符号:
_yywrap,引用自:
ccMsRtp7.o中的_yylex
ccMsRtp7.o中的输入
_main,引用自:
开始于crt1.10.6.o
ld:找不到符号
collect2:ld返回1退出状态

lex --version告诉我我实际上使用'flex 2.5.35',尽管ls -fla`which lex` isn符号链接。任何想法为什么输出不会编译?

解决方案

Flex手册


我得到一个关于undefined yywrap()的错误。



你必须提供你自己的yywrap()函数,或者链接到libfl。 a(提供一个),或者使用

 %选项noyywrap 

在源代码中表示你不想使用yywrap()函数。

另外:


当扫描器从
YY_INPUT接收到
文件结束符指示时,它会检查yywrap()函数。如果
yywrap()返回false(零),则假定
函数已经提前并设置yyin指向另一个输入文件
,然后继续扫描。如果它返回
true(非零),则扫描器终止,向其调用者返回0
。请注意,在任一情况下,起始条件保持不变;它不会恢复为INITIAL。



When I attempt to compile the output of this trivial lex program:

# lex.l
integer   printf("found keyword INT");

using:

$ gcc lex.yy.c

I get:

Undefined symbols:
  "_yywrap", referenced from:
      _yylex in ccMsRtp7.o
      _input in ccMsRtp7.o
  "_main", referenced from:
      start in crt1.10.6.o
ld: symbol(s) not found
collect2: ld returned 1 exit status

lex --version tells me I'm actually using 'flex 2.5.35' although ls -fla `which lex` isn't a symlink. Any ideas why the output won't compile?

解决方案

From the Flex manual:

I get an error about undefined yywrap().

You must supply a yywrap() function of your own, or link to libfl.a (which provides one), or use

%option noyywrap

in your source to say you don't want a yywrap() function.

Also:

When the scanner receives an end-of-file indication from YY_INPUT, it then checks the yywrap() function. If yywrap() returns false (zero), then it is assumed that the function has gone ahead and set up yyin to point to another input file, and scanning continues. If it returns true (non-zero), then the scanner terminates, returning 0 to its caller. Note that in either case, the start condi- tion remains unchanged; it does not revert to INITIAL.

这篇关于无法编译lex的输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆