gpt4 book ai didi

gcc - 无法编译 lex 的输出

转载 作者:行者123 更新时间:2023-12-04 16:26:33 25 4
gpt4 key购买 nike

当我尝试编译这个微不足道的 lex 程序的输出时:

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

使用:
$ gcc lex.yy.c

我得到:
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 告诉我我实际上使用的是“flex 2.5.35”,尽管 ls -fla `which lex` 不是符号链接(symbolic link)。为什么输出无法编译的任何想法?

最佳答案

来自 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.

关于gcc - 无法编译 lex 的输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2612394/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com