4
votes

I created a simple Flex file to read and return tokens from a file. I generated the scanner file using the command flex -c++ scanner.l. When trying to compile the generated lex.yy.cc file I am getting the error as:

Fatal error: FlexLexer.h: No such file or directory

The include folder of flex contains the FlexLexer.h file. I also tried by copying the file to the same folder where lex.yy.cc resides. Still the error exists.

I am using Windows7.

How can I solve this problem. Thank You

1
what compiler/IDE are you using?user685684
@user685684 : I compiled using gcc (g++ lex.yy.cc) from the command prompt. I also tried using Dev C++ and Visual Studio 2010.Jackzz

1 Answers

4
votes

The generated scanner uses the line:

#include <FlexLexer.h>

which means that the FlexLexer.h file will be searched for in system include directories. If you correctly install flex, the installation should put the FlexLexer.h file in some system include directory. If you just download the flex source and compile it without installing it, that won't work. And it might not work in the Windows environment either; I've never tried.

If you have no other alternative, and you're using gcc, you can tell gcc to use the include directory in the flex source tree as a system include directory using the command-line option -isystem /path/to/flex/include. There's almost certainly a VS2010 equivalent but I have no idea what it is.