Fatal error: FlexLexer.h: No such file or directory
Asked Answered
G

1

6

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

Garibold answered 10/9, 2014 at 6:34 Comment(2)
what compiler/IDE are you using?Masseter
@Masseter : I compiled using gcc (g++ lex.yy.cc) from the command prompt. I also tried using Dev C++ and Visual Studio 2010.Garibold
B
5

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.

Bestir answered 10/9, 2014 at 15:29 Comment(9)
I have installed flex in my system and the include folder contains the required header file. Anyway I'll try using the command line option you have told. ThankyouGaribold
I tried using the command line option. Then it is showing the eror as C:\GnuWin32\include/FlexLexer.h:47:22: fatal error: iostream.h: No such file or directory .Garibold
@ANU: You have an old version of flex. You should get a newer one. You could edit FlexLexer.h to change line 47 from #include <iostream.h> (which has never been correct) to #include <iostream>, but I think there are other problems with the C++ skeleton for those old flex versions.Bestir
Ok.. Thank you for your great help.. I was really stuck on the way without knowing what to do.. Thanks a lotGaribold
FYI: On Ubuntu 18.04 in addition to the flex package you also need to install libfl-dev in order to get FlexLexer.h.Dagda
@Dave: Yes, which is a really bad packaging decision IMHO. But what does that have to do with the question, which is about Windows, not Ubuntu? (At least, libfl-dev is on the recommended list for flex, so it usually gets installed.)Bestir
@Bestir I realize the question was Windows specific but I just encountered the same problem on Ubuntu and this was the first Google result. I figured a comment might help others that look here first.Dagda
@Dave: Ok, that's cool. An even better solution would be to ask and self-answer a question with the tag ubuntu, since it's not the same problem (although it has the same symptom) nor is it the same solution (not apt-get for mingw). It also happens with debian (which is the upstream provider for the packaging.)Bestir
In case anyone wonders on how to fix the windows issue, here a github repo that made a version of flex for windows: github.com/lexxmark/winflexbison/releases You can download the release from there, add the environment path to point to that executable of "win_flex" and you should be good to go. As always, read the docs in that repoNewsman

© 2022 - 2024 — McMap. All rights reserved.