Search code examples
c++cwindowsflex-lexerlex

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


I am using 64 bit Windows 7 OS. I have installed 32 bit Flex and Bison from Sourceforge as per the following instructions: http://www.surajgaikwad.com/2013/10/compile-lex-and-yacc-progs-on-windows.html

The only difference is I am not using dev-cpp but I am using mingw cpp as dev-cpp was giving me an error.

Now, I have written a lexical analyzer and I execute the following:

a) When I compile it using flex using the following command, it compiles successfully: flex test.l

b) When I compile the lex.yy.c file produced by step (a), using the following command, it executes OK as well: cpp lex.yy.c

c) However, when I try to send this output to an executable file using the command: cpp lex.yy.c -o a.exe

This a.exe does not run and gives me an error which says: "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."

The header of the pop-up says "Unsupported 16-Bit Application"

I was under the impression that 64 bit windows should be able to execute any 32 bit or 16 bit application. Moreover, I am puzzled, why the compiler is generating 16-bit application.

May I request you to please share your opinion of the probable causes of this issue or any same/similar experiences so that I can investigate further to find the root cause.

Any help would be appreciated. Thanks!


Solution

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

    That's a misapprehension on your part. As per KB896458:

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

    Your cpp compiler is obviously producing a 16-bit application, which 64-bit Windows will not run.

    I'm not entirely sure what compiler you're actually using, since the instructions you link to seem to require gcc for the compilation part, rather than cpp.

    It may be worthwhile trying to figure out what model and version compiler you're using, such as with cpp --help, cpp -h or cpp -?. That will make it easier to track down why you're getting a 16-bit executable.