Daniel
Daniel

Reputation: 6765

Executable file run on double click

I have written and compiled a program in c using gcc through cygwin, and everything works fine when I run the program from the command line; however, when I double-click the executable file, the command window briefly flashes on the screen, but nothing happens. Any ideas why this could be? I am using Windows 7.

Upvotes: 0

Views: 1772

Answers (4)

robert petranovic
robert petranovic

Reputation: 341

When you compile programs inside cygwin, it will link them with dynamic library cygwin.dll. If this file's location is not in your PATH variable, your programs will not run at all outside of cygwin. So, locate cygwin.dll and add that directory to system PATH variable.

Upvotes: 1

SlavaNov
SlavaNov

Reputation: 2485

For example you have program that prints "Hello World!" to command line. It will print "Hello World!" if it's opened from cmd, but if you double click on it, it print it and immediatly close the window.

Try getch() to prevent it. It will print "Press any key to continue".

Upvotes: 1

nobsid
nobsid

Reputation: 186

Cygwin requires cygwin.dll to be in the PATH when executing files compiled for that environment. When you compile something with cygwin you are compiling for cygwin.

I would recommend using MinGW instead, if you plan on building programs. When you compile something with mingw you are compiling for windows.

Upvotes: 2

Kevin
Kevin

Reputation: 56129

Is it a graphical application? If not, it's not getting input, so it's probably starting, seeing the EOF (if it checks input at all), then finishing. When it's finished, the terminal window is closed automatically.

Upvotes: 0

Related Questions