0
votes

I'm trying to write a program using flex++, however everytime I try to compile I receive the error message:

FlexLexer.h: No such file or directory

However that header is found on the include folder of flex. I don't have problems compiling lex programs for c, however for c++ with flex++ I can't seem to find a way. I already downloaded flex various times and I don't know if there is a problem with my OS or something like that. My OS is Windows 10. Thank you

1
Insufficient information. Do you include the path to the flex folder in the compiler command line?user4581301
Hi, thanks for your comment. Well the commands I use are only: flex++ ex.l and then g++ lex.yy.cc. I don't know how to give the path of the flex folder to the compiler however.Ricardo Muñoz
give g++ -I <path to flex include folder> lex.yy.cc a tryuser4581301
Does that path refer to where the FlexLexer.h is? if so I think it is this one: C:\Program Files (x86)\GnuWin32\include so should I just copy that between -I and lex.yy.cc?Ricardo Muñoz
Not sure. I'd expect it to be in some folder that ends in flex\include. You said in the question you'd found the location of FlexLexer.h on your system. You want -I and then that location.user4581301

1 Answers

0
votes

Including should be pretty straightforward once you understand how it works.

Let's look at some different ways you can include a file:

#include "FlexLexer.h"

The quotes tell the compiler to look for the file FlexLexer.h in the same folder as the file being compiled. That is it, it won't look anywhere else.

Now if we change the quotes to brackets:

#include <FlexLexer.h>

This tells the compiler to look for FlexLexer.h in the same folder first, but then if it isn't found it will go through the list of include paths looking for it there, too.

Assuming you are using VisualStudio, there is both a system list of include paths (see Tools > Options > Projects and Solutions > VC++ Directories) and a project list of include paths (right click on the Project in the Solution Explorer, Properties > VC++ Directories). Both of these lists are traversed.

Finally, you can also add subdirectory qualifies to the include, e.g.:

#include "Win\FlexLexer.h"

or

#include <Win\FlexLexer.h>

As you might guess, it looks for the path under either the current directory in the both examples and also under the include path list in the later example. Regardless, the first time the file is found the search will stop and the compiler will use it. So be careful if there are headers will duplicate names in different libraries!