C 中的 Flex 在 64 位 Windows 7 机器上编译时产生不受支持的 16 位应用程序

Flex in C produces Unsupported 16 bit Application while compiling on 64 bit Windows 7 Machine

我正在使用 64 位 Windows7 OS。我已经按照以下说明从 Sourceforge 安装了 32 位 Flex 和 Bison: http://www.surajgaikwad.com/2013/10/compile-lex-and-yacc-progs-on-windows.html

唯一的区别是我没有使用 dev-cpp,但我使用的是 mingw cpp,因为 dev-cpp 给我一个错误。

现在,我已经编写了一个词法分析器并执行了以下命令:

a) 当我使用以下命令使用 flex 编译它时,它编译成功: 弹性 test.l

b) 当我编译由步骤 (a) 生成的 lex.yy.c 文件时,使用以下命令,它也执行 OK: cpp lex.yy.c

c) 但是,当我尝试使用以下命令将此输出发送到可执行文件时: cpp lex.yy.c -o a.exe

这个 a.exe 不 运行 并给我一个错误,上面写着: "This version of E:...\src\a.exe is not compatible with the version of Windows you're running. Check your computer's system information to see whether you need a x86 (32-bit) or x64 (64-bit) version of the program, and then contact the software publisher."

pop-up的header表示"Unsupported 16-Bit Application"

我的印象是 64 位 windows 应该能够执行任何 32 位或 16 位应用程序。而且,我很困惑,为什么编译器生成16位应用程序。

我可以请求您分享您对此问题的可能原因或任何 same/similar 经验的看法,以便我可以进一步调查以找到根本原因。

如有任何帮助,我们将不胜感激。谢谢!

I was under the impression that 64 bit windows should be able to execute any 32 bit or 16 bit application.

这是你的误解。根据 KB896458:

64-bit versions of Windows do not support 16-bit components, 16-bit processes, or 16-bit applications.

您的 cpp 编译器显然正在生成 16 位应用程序,而 64 位 Windows 不会 运行。

我不完全确定您实际使用的是什么编译器,因为您 link 的指令似乎需要 gcc 作为编译部分,而不是 cpp

可能值得尝试弄清楚您使用的是什么型号和版本的编译器,例如 cpp --helpcpp -hcpp -?。这将使您更容易找到 为什么 您会获得 16 位可执行文件。

从 gcc 参数中删除“-c”。为我工作 :D