gpt4 book ai didi

visual-c++ - vc++下编译bison和flex程序时unistd.h相关困难

转载 作者:行者123 更新时间:2023-12-03 03:47:33 26 4
gpt4 key购买 nike

我正在使用 bison 和 flex(通过 cygwin 下载)和 vc++。当我编译程序时出现错误:

...: 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 吗?如果是的话如何编写才能消除这些错误?

最佳答案

isatty 由词法分析器用来确定输入流是终端还是管道/文件。词法分析器使用此信息来更改其缓存行为(词法分析器在不是终端时读取大量输入)。如果您知道您的程序永远不会以交互方式使用,则可以将 %option never-interactive 添加到您的词法分析器中。当程序通过用户输入运行时,请使用%option Interactive。当需要两种用途时,您可以生成一个交互式词法分析器,这在批处理模式下使用时会带来性能损失,或者提供您自己的 isatty 函数。

关于visual-c++ - vc++下编译bison和flex程序时unistd.h相关困难,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2793413/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com