52

I've had Eclipse for Java on my computer for a few years, and decided to install the CDT and learn C. I installed both MinGW and Cygwin and the CDT detects and tries to use them when I make a new project.

I choose File > New C++ Project and choose Hello World C++ Project and the CygwinGCC toolchain. I name the project "asdf" and hit "Build Debug" in the toolbar. The compiler completes without error. I hit Run and nothing happens.

Browsing to the project directory manually and running asdf.exe gives me an error saying:
"The program can't start because cygwin1.dll is missing from your computer. Try reinstalling the program to fix this problem."

The same thing happens using MinGW, only a different dll is missing.
What do I need to do to have a usable .exe?
(I'm running Windows 7 x64 and the newest version of Eclipse and the CDT.)

EDIT: The compiler output is as follows:

**** Build of configuration Debug for project asdf ****

make all 
Building file: ../src/asdf.cpp
Invoking: Cygwin C++ Compiler
g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/asdf.d" -MT"src/asdf.d" -o"src/asdf.o" "../src/asdf.cpp"
cygwin warning:
  MS-DOS style path detected: C:\Users\Shawn\Dropbox\eclipse\asdf\Debug
  Preferred POSIX equivalent is: /cygdrive/c/Users/Shawn/Dropbox/eclipse/asdf/Debug
  CYGWIN environment variable option "nodosfilewarning" turns off this warning.
  Consult the user's guide for more details about POSIX paths:
    http://cygwin.com/cygwin-ug-net/using.html#using-pathnames
Finished building: ../src/asdf.cpp

Building target: asdf.exe
Invoking: Cygwin C++ Linker
g++  -o"asdf.exe"  ./src/asdf.o   
Finished building target: asdf.exe
not2qubit
  • 14,531
  • 8
  • 95
  • 135
Shawn Walton
  • 1,714
  • 2
  • 14
  • 23

3 Answers3

83

This error message means that Windows isn't able to find "cygwin1.dll". The Programs that the Cygwin gcc create depend on this DLL. The file is part of cygwin , so most likely it's located in C:\cygwin\bin. To fix the problem all you have to do is add C:\cygwin\bin (or the location where cygwin1.dll can be found) to your system path. Alternatively you can copy cygwin1.dll into your Windows directory.

There is a nice tool called DependencyWalker that you can download from http://www.dependencywalker.com . You can use it to check dependencies of executables, so if you inspect your generated program it tells you which dependencies are missing and which are resolved.

Nick Garvey
  • 2,980
  • 24
  • 31
phlogratos
  • 13,234
  • 1
  • 32
  • 37
  • It worked! It needed a couple more dlls, too. So I'm assuming the only way to make standalone .exes is to use VisualStudio, then? – Shawn Walton Jul 19 '11 at 19:38
  • 2
    What I should add is that you can copy the DLLs into the same directory as the exe. The exes built by VisualStudio usualy have dependencies too, e.g. to MSVCR71.DLL – phlogratos Jul 19 '11 at 19:49
  • Hello. In my case, mutliple .dll are missing because my folder is called C:\cygwin64\bin. Do you think it's safe to just erase the 64 or is there a smarter way around this? Thanks – Marco Castanho Oct 23 '15 at 11:18
  • 2
    @Marco: Why don't you just add `C:\cygwin64\bin` to your system path? I guess your binary is compiled as 64bit. – phlogratos Oct 25 '15 at 18:44
  • @phlogratos I tried to add it to my PATH (system and user variable PATH) and it didn't work. I also copied it to `C:\` with no favorable result. – Jossie Calderon Jun 29 '16 at 17:12
  • @Jossie Have you tried analyzing your problem with DependencyWalker? – phlogratos Jun 30 '16 at 12:53
  • @phlogratos In DependencyWalker, `CYGWIN1.DLL` is shown as red. What can I do now? – Jossie Calderon Jun 30 '16 at 16:22
  • 2
    @phlogratos I typoed, forgot to add a `;` before the last folder, and also typed `C:cygwin64\bin`. The problem is now resolved. – Jossie Calderon Jun 30 '16 at 17:10
  • 5
    If a program needs cygwin1.dll, does that mean it also requires a cygwin installation? Or can it run on any machine so long as the dll is present? – Steve W May 15 '17 at 14:02
  • 1
    For me it worked when adding `cygwin1.dll` to `C:\windows` directory. – ako Mar 13 '18 at 08:26
  • @ShawnWalton " So I'm assuming the only way to make standalone .exes is to use VisualStudio, then?" -- Why the heck would you assume that? You don't even need VS to run Microsoft's C compiler, let alone all the other compilers that run on Windows. – Jim Balter Jul 13 '18 at 07:39
  • For me, what actually worked was adding the whole of Cygwin bin to my path for Windows 8, legacy support is a female dog... – David Kabii Mar 27 '20 at 08:50
2

You can compile with either Cygwin's g++ or MinGW (via stand-alone or using Cygwin package). However, in order to run it, you need to add the Cygwin1.dll (and others) PATH to the system Windows PATH, before any cygwin style paths.

Thus add: ;C:\cygwin64\bin to the end of your Windows system PATH variable.

Also, to compile for use in CMD or PowerShell, you may need to use:

x86_64-w64-mingw32-g++.exe -static -std=c++11 prog_name.cc -o prog_name.exe

(This invokes the cross-compiler, if installed.)

not2qubit
  • 14,531
  • 8
  • 95
  • 135
  • 1
    Thank you so much for your help @not2qubit. But you forgot to put a colon in the ';C\cygwin64\bin' string, right after 'C'. I think it would be better to edit your answer. Because I was a bit confused at first. Bests ... – SANN May 07 '20 at 20:31
  • Hi @SANN I've now fixed. Thanks – not2qubit May 08 '20 at 05:39
0

To add to this and save someone another google, just do this in cmd:

set PATH=%PATH%;C:\cygwin64\bin