原因:flex版本>2.5.4时的一个不兼容动作
处理方法:
当调试出现 undefined reference to `yywrap'得时候解决办法。
%option noyywrap
或者是链接时候使用-lfl参数来使用fl库中得函数。
当然也可以自己添加一个yywrap函数。返回个1就行了。
更多原因说明:
-
As previously noted by another poster this is a problem with the flex version on your system. If you use a flex with a higher version than 2.5.4 you're out of luck, unless you patch the sources. The reason for this is that the people developing flex had the "interesting" idea of changing the way the lexer parses the language file.
The fix is to downgrade your flex or to patch cfg-lex.l with a %option field disabling yywarp. From the top of my head it should read:
%option noyywrap Or you define the options as follows (I think):%{ prototype functionname(parameters); %}
#define yywrap() 1
更好的办法是定义:
int yywrap()
{
return(1);
}
关于yywrap更详细的信息可以参考unix的lex manual
http://www.scit.wlv.ac.uk/cgi-bin/mansec?1+lex
int yywrap(void)
Called by yylex at end-of-file; the default yywrap
always will return 1. If the application requires
yylex to continue processing with another source of
input, then the application can include a function
yywrap, which associates another file with the exter-
nal variable FILE *yyin and will return a value of
zero.
或flex的参考手册(这个貌似更广泛一点):
http://www.gnu.org/software/flex/manual/html_mono/flex.html
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 condition remains unchanged; it does notrevert to INITIAL.
If you do not supply your own version of `yywrap()', then you must either use `%option noyywrap' (in which case the scanner behaves as though `yywrap()' returned 1), or you must link with `-lfl' to obtain the default version of the routine, which always returns 1.
参考网址:http://stackoverflow.com/questions/1811125/undefined-reference-to-yywrap