无法编译 lex 的输出
当我尝试编译这个简单的 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` 不是符号链接。有什么想法为什么输出无法编译吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
来自Flex 手册 :
另外:
From the Flex manual:
Also:
正如 Eli 的回答所暗示的那样,这不是一个简单的 lex 程序。这是一个简单的 lex 文件,因此是程序的一部分,但它(像任何 lex 文件一样)需要与一些 C 代码结合起来才能形成完整的程序。特别是,您仍然需要一个 main 函数(用 C 或 C++ 或其他语言编写,在单独的文件中),并且还需要编写一个 yywrap 函数它提供了 lex 代码和其余 C 代码之间的接口。
As Eli's answer implies, that's not a trivial lex program. It's a trivial lex file, and thus a portion of a program, but it (like any lex file) needs to be combined with some C code to make a complete program. In particular, you still need a
main
function (which you write in C or C++ or something, in a separate file), and you will also need to write ayywrap
function that provides the interface between the lex code and the rest of your C code.