tags:

views:

4478

answers:

2

So I'm trying to run my first hello world prog written in C. I compiled it in eclipse and get no errors, but when I try to run it I get:

"This application has failed to start because cygwin1.dll was not found."

I found this post which seems to indicate I should add it to Windows PATH, and I used this to do that. So now "Path" in my environment variables has ";C:\cygwin\bin\cygwin1.dll" appended to the end. Still no worky. Anyone have a clue what I might be doing wrong? My 'program' just looks like this:

#include <stdio.h>

main()
{
    printf("hello, world\n");
}
+7  A: 

The PATH environment variable needs to include the directory containing cygwin1.dll, not the path to cygwin1.dll itself. So just make sure that PATH has the string "C:\cygwin\bin" in it.

Adam Rosenfield
Haha, I tried C:\cygwin but it didn't occur to me to do C:\cygwin\bin. It works. Thanks. Now I just need to figure out how to get the window to stay for long enough to see the output. :D
Run it from the command line - run cmd.exe (or, better yet, just run Cygwin), navigate to the executable's directory, and run the executable from the command line.
Adam Rosenfield
Or put in a Read after you printf.
EBGreen
Thanks thanks thanks. :D This is so cool :)
+3  A: 

By the way, I implore you not to blindly add a directory containing cygwin1.dll to the system PATH. The path is searched sequentially. If you happen to have older or newer versions of the Cygwin runtime in the path, other programs linked against cygwin1.dll might break horribly (and it's not trivial to figure out what happened unless you know that you're looking for a different DLL version.)

What you should do is copy cygwin1.dll (and other Cygwin DLLs your program might require) into the directory which holds your binary then create an empty (zero byte length) file with the same name as your executable but with .local appended, i.e., if your executable is mytest.exe, you create a file named mytest.exe.local . That will tell the PE loader to first look for required DLLs in the same directory that holds your binary, thus avoiding a lot of headache later on.

Mihai Limbășan