unistd.h related difficulty when compiling bison & flex program under vc++

99封情书 提交于 2019-12-03 09:37:13

isatty is used by the lexer to determine if the input stream is a terminal or a pipe/file. The lexer uses this information to change its caching behavior (the lexer reads large chunks of the input when it is not a terminal). If you know that your program will never be used in an interactive kind, you can add %option never-interactive to you lexer. When the program is run with user input, use %option interactive. When both uses are desired, you can either generate an interactive lexer, which gives a performance loss when used in batch mode, or provide your own isatty function.

Use %option nounistd in your .l file to remove the dependence on unistd.h.

just in case somebody's still this problem, Flex comes with unistd.h within its devel files. I found this here:

http://sourceforge.net/tracker/index.php?func=detail&aid=931222&group_id=23617&atid=379173

to put it short, just make sure your compiler can reach it. in my case it's just adding "C:\GnuWin32\include" to the additional inclusion directories

use win_flex.exe with option --wincompat and you dont need to hack your lex file

tzaman

unistd.h is a UNIX header, so it's not present in VC++; your best bet is probably to compile it using g++ in Cygwin (or mingw/msys). You could also look at this question for other suggestions.

Yariv

I'm using flex 2.5.4 that comes from the GnuWin32 project, which doesn't check for YY_NO_UNISTD_H.

In my version, Flex looks for unistd.h only when being compiled as C++, so you can save yourself all this trouble if your yylval doesn't use any C++ constructs.

I had to use the STL in yylval (using a pointer to make it a POD type), so in order to make flex compile in C++ I created this simple unistd.h:

#include <io.h>

That's all it takes (actually, I could copy the unistd.h file that comes with GnuWin32, like flyontheweb suggests).

P.S. To wrap things up: in Bison I put yylval's required STL header files in %code requires {} and added the current directory to the INCLUDE paths in my makefile.

I am too late but anyway I will share my findings to save someone still looking for answer. In my case having an empty unistd.h file in the location where compiler looks for headers works for me.

Well this post is old but I face the same problem and here is something that should work. WinFlexBison

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!