Flex and Yacc - Cannot find - lfl?

旧巷老猫 提交于 2019-12-01 16:21:02

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

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
%%
 ...
%%
faye

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 :)

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.

For error: cannot find -lflx

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

Otherwise remove the -lfl argument wherever present.

After having a hard time trying to fix the same problem as yours, I installed flex-old:

sudo apt install flex-old

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!