1

I wrote gcc lex.yy.c -o ornek -lfl in command line. Then I get an error as follows:

/usr/bin/ld: cannot find -lfl
collect2: error: ld returned 1 exit status

How can I solve this problem?

rici
  • 234,347
  • 28
  • 237
  • 341
soil
  • 19
  • 6
  • https://unix.stackexchange.com/questions/37971/usr-bin-ld-cannot-find-lfl – melpomene Oct 21 '18 at 14:24
  • Hiw did you install flex? (And are you really using Ubuntu?) Regardless, there is good information here: https://stackoverflow.com/questions/26064096/using-flex-the-lexical-analizer-on-os-x/26064848 – rici Oct 21 '18 at 15:34
  • 1
    @rici I’m using linux mint. I installed writing like sudo apt -get install flex byacc in command line – soil Oct 21 '18 at 15:37

1 Answers1

4

You need to separately install libfl-dev in order to have the fl library.

But you probably don't need that library. It only provides two things, neither of which is particularly useful:

  • A do-nothing definition of yywrap. Instead if using this, avoid the need by placing

    %option noyywrap
    

    in the first section of your flex file.

  • A definition of main which just calls yylex repeatedly. Normally, you will want to write a more interesting main function. But if you want to duplicate the default provided in -lfl, it looks basically like this:

    int main(void) {
      while(yylex()) { }
      return 0;
    }
    
rici
  • 234,347
  • 28
  • 237
  • 341