Using Flex (the lexical analizer) on OS X

回眸只為那壹抹淺笑 提交于 2019-12-10 20:47:48

问题


I've got a file, test.lex, which I run through as

$ flex test.lex

That gives me lex.yy.c, which I try to compile with:

$ gcc lex.yy.c -lfl

This gives me the error ld: library not found for -lfl. I know the Flex specification is correct and lex.yy.c compiles fine on a Linux machine. Any suggestions?

Edit: I'm using the flex supplied by Apple.


回答1:


Some systems make libfl a separate package from flex, as it is rarely needed. The libfl library just contains two functions:

int main() {
    while (yylex());
    return 0;
}

int yywrap() {
    return 1;
}

Normally you'll want your own main function rather than the one from libfl, and defining yywrap yourself is trivial. Alternately, you can use %option noyywrap and not need it at all.

In your case, try just getting rid of the -lfl option. If you get an error about yywrap, add
%option noyywrap to the first section of your test.lex file.




回答2:


old topic but accepted answer did not help me.
so I'm adding this answer.

on macos use -ll (as in "library lex").
valid for macos 10.14 mojave.

also as @Chris Dodd said you can get rid of this dependency by specifying %option noyywrap in .l file and providing own main routine .y file.



来源:https://stackoverflow.com/questions/26064096/using-flex-the-lexical-analizer-on-os-x

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!