【发布时间】:2011-02-07 18:24:16
【问题描述】:
我对 flex 完全陌生。
我在使用 flex 时遇到构建错误。也就是说,我使用 flex 生成了一个 .c 文件,并且在运行它时出现此错误:
1>lextest.obj : error LNK2001: unresolved external symbol "int __cdecl isatty(int)" (?isatty@@YAHH@Z)
1>C:\...\lextest.exe : fatal error LNK1120: 1 unresolved externals
这是我正在使用的 lex 文件(取自 here):
/*** Definition section ***/
%{
/* C code to be copied verbatim */
#include <stdio.h>
%}
/* This tells flex to read only one input file */
%option noyywrap
%%
/*** Rules section ***/
/* [0-9]+ matches a string of one or more digits */
[0-9]+ {
/* yytext is a string containing the matched text. */
printf("Saw an integer: %s\n", yytext);
}
. { /* Ignore all other characters. */ }
%%
/*** C Code section ***/
int main(void)
{
/* Call the lexer, then quit. */
yylex();
return 0;
}
同样,为什么我必须在 lex 语法代码中放置一个“主”函数?我想要的是能够调用 yylex();来自另一个 c 文件。
【问题讨论】:
标签: windows lex flex-lexer