Hai*_*ang 24 cygwin bison visual-c++ flex-lexer
我正在使用bison&flex(通过cygwin下载)和vc ++.当我编译程序时,我收到一个错误:
...: fatal error C1083: Cannot open include file: 'unistd.h': No such file or directory
Run Code Online (Sandbox Code Playgroud)
flex生成的文件中的相应代码是:
#ifndef YY_NO_UNISTD_H
/* Special case for "unistd.h", since it is non-ANSI. We include it way
* down here because we want the user's section 1 to have been scanned first.
* The user has a chance to override it with an option.
*/
/* %if-c-only */
#include <unistd.h>
/* %endif */
/* %if-c++-only */
/* %endif */
#endif
Run Code Online (Sandbox Code Playgroud)
如果我在flex文件(.l)中定义YY_NO_UNISTD_H,则此错误将消失,但我还会收到其他几个错误:
...: error C2447: '{' : missing function header (old-style formal list?)
...: warning C4018: '<' : signed/unsigned mismatch
...: error C3861: 'isatty': identifier not found
Run Code Online (Sandbox Code Playgroud)
我该如何解决这个问题?
所有这些错误都发生在flex生成的扫描仪中.
我知道这是因为unistd.h在windows中不存在.我是否必须编写自己的unistd.h?如果是这样,如何编写它以消除这些错误?
Rud*_*udi 17
isatty词法分析器使用词来确定输入流是终端还是管道/文件.词法分析器使用此信息来更改其缓存行为(词法分析器在不是终端时读取大块输入).如果您知道您的程序永远不会以交互式方式使用,您可以添加%option never-interactive词法分析器.使用用户输入运行程序时,请使用%option interactive.当需要两种用途时,您可以生成交互式词法分析器,在批处理模式下使用时会导致性能下降,或者提供您自己的isatty功能.
Dr.*_* RE 15
%option nounistd在您的.l文件中使用以消除对依赖性unistd.h.
小智 9
为了防止有人仍然存在这个问题,Flex在其开发文件中附带了unistd.h.我在这里找到了这个:
http://sourceforge.net/tracker/index.php?func=detail&aid=931222&group_id=23617&atid=379173
简而言之,只需确保您的编译器可以达到它.在我的情况下,它只是将"C:\ GnuWin32\include"添加到其他包含目录中