问题
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