Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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

1 Answer 1

up vote 6 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
2  
installing flex-static package solved the problem –  NPK May 6 '12 at 14:40
1  
+1 to flex-static –  kolinko Feb 3 '13 at 12:24

Your Answer

 
discard

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.