tags:

views:

4291

answers:

8

I created a C file in Eclipse on Windows and then used Cygwin to navigate to the directory. I called gcc on the C source file and a.exe was produced. How do I execute a.exe in the Cygwin shell?

+5  A: 

./a.exe at the prompt

Allain Lalonde
+3  A: 

you should just be able to call it by typing in the file name. You may have to call ./a.exe as the current directory is usually not on the path for security reasons.

Kibbee
+2  A: 

just type ./a in the shell

Bedwyr Humphreys
A: 

Just call it

> a

Make sure it will be found (path).

kaiz.net
A: 

@allain:

Thank you. Apparently, gcc doesn't behave like the one described in The C Programming language, where it says that the command cc helloworld.c produces a file called a.out which can be run by typing a.out on the prompt.

Instead, a file called a.exe was produced by both gcc and cc and it can not be run by typing a.exe on the prompt.

Thanks again.

Thomas Owens
+1  A: 

To execute a file in the current directory, the syntax to use is: ./foo

As mentioned by allain, ./a.exe is the correct way to execute a.exe in the working directory using Cygwin.

Note: You may wish to use the -o parameter to cc to specify your own output filename. An example of this would be: cc helloworld.c -o helloworld.exe.

Jason Weathered
+1  A: 

Thomas wrote:

Apparently, gcc doesn't behave like the one described in The C Programming language

It does in general. For your program to run on Windows it needs to end in .exe, "the C Programming language" was not written with Windows programmers in mind. As you've seen, cygwin emulates many, but not all, features of a POSIX environment.

Adam Mitz
+1  A: 

Apparently, gcc doesn't behave like the one described in The C Programming language, where it says that the command cc helloworld.c produces a file called a.out which can be run by typing a.out on the prompt.

A Unix hasn't behaved in that way by default (so you can just write the executable name without ./ at the front) in a long time. It's called a.exe, because else Windows won't execute it, as it gets file types from the extension.

Bernard