2

I have no special code to share to ask this, but I wrote a C++ code (which could even be a simple Hello World program) compiled to an exe file, requires the cygwin1.dll available either via %path% or in the same folder as the exe to run (for runtime).

If it were libstdc++-6.dll needed I could have done something like use the tag -static or -static-libstdc++. But, what can I do to not depend upon cygwin1.dll file for exe execution? Should I use some other compiler instead?

Ps: I am expecting some kinda solution similar to this if it makes sense. MinGW .exe requires a few gcc dll's regardless of the code?

Also, I do not want to create Or use a separate installer to add the dll to the right place for my case.

Thinker-101
  • 554
  • 5
  • 19
  • 2
    My snarky reply would be to not Cygwin at all. My opinion of Cygwin is not high. It sufficed back in the day, but far superior tools exist now. – sweenish May 23 '22 at 18:59
  • You shouldn't use Cygwin unless you specifically need POSIX emulation that it provides. Your default GCC choice of Windows should be [MSYS2](https://stackoverflow.com/q/30069830/2752075). – HolyBlackCat May 23 '22 at 18:59
  • @HolyBlackCat What if I need -pthread? To be honest I need that totally and which is why I went for cygwin without giving much thought to other compilers. Also my actual code needs c++14 to run properly. I am pretty new to c++ world. I hope msys2 supports it. – Thinker-101 May 23 '22 at 19:04
  • 1
    MSYS2 GCC does support `-pthread` (only the original MinGW didn't support threads). *"my actual code needs c++14"* This isn't a problem at all, you get latest GCC (or Clang, if you prefer). – HolyBlackCat May 23 '22 at 19:07
  • @sweenish Do you have any recommendations I could try? – Thinker-101 May 23 '22 at 19:09
  • Cygwin in particular relies on its own libraries, because they provide the shims that allow Unix calls to work on Windows. – Mark Ransom May 23 '22 at 19:12
  • 1
    It all varies. I gave my students a Docker container. If you need a Windows executable, getting minGW through MSYS2 is my preferred method. If you just need to be able to write the code, WSL might fit the bill. It depends on where you want to write your code, and for what purpose. – sweenish May 23 '22 at 19:23
  • I think Cygwin is great for its compatibility with POSIX and for its exhaustive and up-to-date package distribution system. But it is inappropriate to build Windows programs that needs to be distributed out of Cygwin ecosystem. – prapin May 23 '22 at 19:34

1 Answers1

1

As discussed in comments, the native gcc inside Cygwin targets Cygwin. You want the GCC targeting mingw32 not the one targeting Cygwin. While you can install that GCC inside Cygwin as a cross compiler, the native GCC from MSYS works just fine and I too would recommend that.

Note that if you need a library that isn't available in MINGW, pulling the one from Cygwin will essentially never work. Consider this a hard line: never mix Cygwin dependent dlls with non-Cygwin dependent dlls. Treat Cygwin as a subsystem that happens to be startable directly from Win32 rather than a Win32 library.

MINGW has had pthread for awhile; however many times the port doesn't work. If the pthread-using program calls fork(), it will not work. That's when you need Cygwin.

Joshua
  • 40,822
  • 8
  • 72
  • 132