Executable file generated using GCC under cygwin

cygwingcc

I am using Cygwin and have GCC (version 4.3.4 20090804 (release) 1 ) installed as Cygwin package.

When I built C code using GCC under Cygwin shell, the generated executable output file is a executable of type (PE32 executable for MS Windows (console) Intel 80386 32-bit) and it can only be executed/run under Cygwin shell, not as standalone .exe on Windows shell/command prompt. If I try to run it standalone on Windows command prompt it gives an error window saying "The program can't run because cygwin.dll is missing from your computer".

  1. How can one make this .exe standalone, which can be executed on a command prompt of any other system or even in my own system?

  2. I thought GCC under Cygwin would build a Linux executable (ELF 32-bit LSB executable), but it's not so. How can I use the gcc-cygwin combination to generate a *.out kind of Linux executable file?

  3. Also, I cannot run a Linux executable generated on a Linux-gcc combination to execute under Cygwin.

Any pointers would be helpful.

Best Answer

Despite widespread rumours, Cygwin is not a Linux emulator, i.e. it doesn't produce or run Linux executables. For that you'll need a virtual machine or coLinux.

Instead, Cygwin is a compatibility layer, which aims to implement as much as possible of the POSIX and Linux APIs within Windows. This means that programs have to be compiled specifically for Cygwin, but it also means that it's better integrated with Windows, e.g. it lets you mix POSIX and Windows APIs in the same program.

It's the cygwin1.dll that provides that compatibility layer. If you build non-Cygwin executables using gcc-3's -mno-cygwin switch or one of the MinGW compilers, then of course you can't use any POSIX/Linux-specific APIs, and any such calls will need to be replaced with Windows equivalents.

Related Topic