Flex and Yacc - Can't find - lfl?

Hi, I'm flying Lex and Yak. I created the following lex program.

%{ #include <stdio.h> %} %% [0123456789]+ printf("NUMBER\n"); [a-zA-Z][a-zA-Z0-9]* printf("WORD\n"); %% 

I am trying to run it using the following commands:

  • lex example1.l
  • cc lex.yy.c -o example1 -ll

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

When I enter the second form of the command, I get an error message:

 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 this error but no luck. Since I'm new to Lex's programming, I don't understand how to fix this. Any help would be appreciated. Thank you very much in advance.

+7
source share
5 answers

To compile lex code, firstly, you must install flex on your computer. If so, there will be a libfl.a file. In my machine, I installed flex in 'C: \ GnuWin32 \ lib'

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

+5
source

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

 %option noyywrap %% ... %% 
+4
source

I ran into the same problem and so I checked it on the Internet and found a solution by workcaptchabypass published June 3, 2011 6:44 here

he said:

You can add this function instead and usually compile

 yywrap() { } 

And so I put the code in the .lex file before the main function. After that, he decided how it should be :)

+2
source

I ran into this problem when porting TXR to Windows using MinGW.

MinGW has a flexible 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

A workaround is to use -L/usr/lib to -lfl . But think about it: it's a hack. What for? Since the path /usr/lib/ belongs to MinGW, the compilation runtime is.

/usr/lib not where it is supposed that the tool chain should look for libraries for the Windows program being created (which is not in the library search path!)

That is, we effectively steal our own library of build machines in a cross-compilation job.

It looks like you cross-compile, say, Fedora on Ubuntu, and help the Ubuntu static library in /usr/lib , which is not in the Fedora cross-program set (taking advantage of the fact that the architecture and format of the object file are the same).

This is definitely a mistake in how Flex is “packaged” in MingW.

+1
source

For error: cannot find -lflx

In your change to Makefile: LEXLIB = -lfl to LEXLIB = .

Otherwise, remove the -lfl argument, wherever it is.

0
source

All Articles