我正在使用带有 vc++ 的 bison 和 flex(通过 cygwin 下载)。当我编译程序时出现错误:
...: fatal error C1083: Cannot open include file: 'unistd.h': No such file or directory
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
如果我在 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
我该如何解决这个问题?
所有这些错误都发生在 flex 生成的扫描仪中。
我知道这是因为 unistd.h 在 Windows 中不存在。我必须编写自己的 unistd.h 吗?如果是这样,如何编写它以消除这些错误?