Using Flex (the lexical analizer) on OS X
Asked Answered
S

2

9

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.

Serpens answered 26/9, 2014 at 16:24 Comment(0)
G
10

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.

Geis answered 26/9, 2014 at 17:12 Comment(3)
Interesting. I had to both add %option noyywrap to test.lex and leave off -lfl as one would expect, but I wonder why OS X couldn't find libfl?Serpens
probably because you don't have it installed.Geis
I assumed that since I have the flex binary, I have libfl. What I do have is libl.a, which seems to provide the same functionality. I'm using the flex supplied by Apple.Serpens
S
4

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.

Stephi answered 11/5, 2019 at 4:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.