未定义的yywrap引用 [英] Undefined Reference To yywrap
问题描述
我有一个使用Flex(Lexical Analyzer)的简单语言",就像这样:
I have a simple "language" that I'm using Flex(Lexical Analyzer), it's like this:
/* Just like UNIX wc */
%{
int chars = 0;
int words = 0;
int lines = 0;
%}
%%
[a-zA-Z]+ { words++; chars += strlen(yytext); }
\n { chars++; lines++; }
. { chars++; }
%%
int main()
{
yylex();
printf("%8d%8d%8d\n", lines, words, chars);
}
我运行了flex count.l
,一切正常,没有错误或警告,然后当我尝试执行cc lex.yy.c
时,出现了以下错误:
The I run a flex count.l
, all goes ok without errors or warnings, then when I try to do a cc lex.yy.c
I got this errors:
ubuntu @ eeepc:〜/Desktop $ cc lex.yy.c
/tmp/ccwwkhvq.o:在函数yylex': lex.yy.c:(.text+0x402): undefined reference to
yywrap'
中 /tmp/ccwwkhvq.o:在函数input': lex.yy.c:(.text+0xe25): undefined reference to
yywrap'
中 collect2:ld返回1个退出状态
ubuntu@eeepc:~/Desktop$ cc lex.yy.c
/tmp/ccwwkhvq.o: In functionyylex': lex.yy.c:(.text+0x402): undefined reference to
yywrap'
/tmp/ccwwkhvq.o: In functioninput': lex.yy.c:(.text+0xe25): undefined reference to
yywrap'
collect2: ld returned 1 exit status
怎么了?
推荐答案
扫描程序在文件末尾调用此函数,因此您可以将其指向另一个文件并继续扫描其内容.如果不需要,请使用
The scanner calls this function on end of file, so you can point it to another file and continue scanning its contents. If you don't need this, use
%option noyywrap
扫描仪规格中的
.
in the scanner specification.
尽管禁用yywrap
当然是最好的选择,但也可以与-lfl
链接,以使用flex提供的库fl
(即libfl.a
)中的默认yywrap()
函数. Posix要求该库可与链接器标志-ll
一起使用,并且默认的OS X安装仅提供该名称.
Although disabling yywrap
is certainly the best option, it may also be possible to link with -lfl
to use the default yywrap()
function in the library fl
(i.e. libfl.a
) provided by flex. Posix requires that library to be available with the linker flag -ll
and the default OS X install only provides that name.
这篇关于未定义的yywrap引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!