Flex and Yacc - Cannot find - lfl?

sap picture sap · Apr 16, 2012 · Viewed 20.5k times · Source

Hi I'm learing Lex and yacc. I created the following lex program.

%{
#include <stdio.h>
%}

%%
[0123456789]+           printf("NUMBER\n");
[a-zA-Z][a-zA-Z0-9]*    printf("WORD\n");
%%

I'm trying to run it using the following commands:

  1. lex example1.l
  2. cc lex.yy.c -o example1 -ll

also tried cc lex.yy.c -o example1 -lfl

When I enter the second command form above, I get error:

D:\workdir\flexyacc\Test3>gcc lex.yy.c -o Test -lfl
C:\Dev-Cpp\bin\..\lib\gcc\mingw32\3.4.2\..\..\..\..\mingw32\bin\ld.exe: cannot find -lfl
collect2: ld returned 1 exit status

I tried googling this error but no luck so far. Since I'm new in Lex programming, I'm not understanding how to fix this. Any help will be greatly appreciated. Thank so much in advance.

Answer

Karthik picture Karthik · Apr 5, 2013

To compile the lex code, firstly you should have installed flex in your machine. If so , there will a file libfl.a. In my machine I've installed flex in 'C:\GnuWin32\lib'

gcc lex.yy.c -L"C:\GnuWin32\lib" -lfl