Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flex and Yacc - Cannot find - lfl?

Tags:

yacc

lex

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.

like image 727
sap Avatar asked Apr 16 '12 14:04

sap


4 Answers

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

like image 148
Karthik Avatar answered Nov 14 '22 04:11

Karthik


I encountered the same problem and so i checked it out in the Internet and found a solution by workingcaptchabypass posted June 3, 2011 6:44 PM here

he said:

You could add this function instead and compile normally

yywrap()
{
}

And so i supplied the code in the .lex file before the main function. After doing that, it worked out the way it should :)

like image 43
faye Avatar answered Nov 14 '22 04:11

faye


If you are using lex + yacc you can remove -lfl if you define yywrap function or, even better, if you use noyywrap option:

%option noyywrap
%%
 ...
%%
like image 9
JJoao Avatar answered Nov 14 '22 05:11

JJoao


I have run into this issue when porting TXR to Windows using MinGW.

MinGW has a flex library for itself, but does not export it to the environment.

See here: http://lists.nongnu.org/archive/html/txr-users/2011-10/msg00001.html

The workaround is to use -L/usr/lib before -lfl. But think about this: it is a hack. Why? Because the path /usr/lib/ belongs to MinGW, the compilation environment's run-time.

/usr/lib is not where the toolchain is supposed to find libs for the Windows program being built (which is it's not in the library search path!)

That is to say, we are effectively stealing the build machine's native library in a cross-compile job.

This is like if you were cross-compiling, say, a Fedora program on Ubuntu, and helping yourself to Ubuntu's static library in /usr/lib that happens to be missing in the Fedora cross toolchain (taking advantage of the fact that the architecture and object file format happens to be the same).

It's definitely a bug in the way Flex is "packaged" in MingW.

like image 2
Kaz Avatar answered Nov 14 '22 05:11

Kaz