Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Executable file generated using GCC under cygwin

Tags:

gcc

cygwin

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.

like image 659
goldenmean Avatar asked Nov 10 '10 10:11

goldenmean


People also ask

What is the default executable name generated by gcc?

By default, gcc assumes that you want to create an executable program called a.exe. Here are the common options that you'll use to change what gcc does. To change where the output file goes, use the -o option, like "gcc hello. c -o hello.exe".

Is gcc an executable?

@CesarB: Yes, the gcc call makes 'your-executable-name' executable by default. Some systems might have a rename command, but mv is the usual way to rename a file.


1 Answers

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.

like image 100
ak2 Avatar answered Sep 24 '22 16:09

ak2