未定义的yywrap引用 [英] Undefined Reference To yywrap

查看:298
本文介绍了未定义的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 function yylex': lex.yy.c:(.text+0x402): undefined reference toyywrap'
/tmp/ccwwkhvq.o: In function input': lex.yy.c:(.text+0xe25): undefined reference toyywrap'
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屋!

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