Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

After running the following command:

g++ lex.yy.c -lfl

I get the following error:

/usr/bin/ld: cannot find -lfl

How can I solve it?

share|improve this question
What distribution/OS are you using? How did you install flex (if that's what you're using)? – Mat May 5 '12 at 8:57
up vote 8 down vote accepted

lex.yy.c is the default output file name for lex, the lexical analyzer preprocessor for C (and C++). The linker (ld) is looking for a file called libfl.so (if linking dynamically; it would be libfl.a if linking statically). This is the runtime library required by lexers generated by Flex, a lex implementation.

If you generated lex.yy.c yourself with flex, check that Flex is installed correctly. In addition to having the flex executable in your path, you need to have libfl.so and libfl.a (and libfl_pic.a if it exists) in your library search path (typically /usr/lib or /usr/local/lib, depending on whether Flex came from a system package or not). If you have Flex in a non-standard location, specify the library search path with -L:

~/software/flex/bin/flex mylexer.l
g++ lex.yy.c -L ~/software/flex/lib -lfl
share|improve this answer
installing flex-static package solved the problem – NPK May 6 '12 at 14:40
+1 to flex-static – kolinko Feb 3 '13 at 12:24

Installing the flex-devel.x86_64 package in my SciOs distro worked for me.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.