1

With the following C code:

int main() {}

I compile under MSYS2 using gcc -o m2 m2.c . This gcc is the one installed by pacman -S gcc; version 4.9.2 target x86_64-pc-msys.

I copy m2.exe and msys-2.0.dll to a directory on another PC with a Cygwin installation. If I run m2.exe from a command prompt it executes correctly, however executing from a Cygwin Bash shell I get the error:

  3 [main] m2 (4552) C:\Temp\m2.exe: *** fatal error - cygheap base mismatch detected - 0x180305408/0x180320400. 
This problem is probably due to using incompatible versions of the cygwin DLL.
Search for cygwin1.dll using the Windows Start->Find/Search facility
and delete all but the most recent version.  The most recent version *should*
reside in x:\cygwin\bin, where 'x' is the drive on which you have
installed the cygwin distribution.  Rebooting is also suggested if you
are unable to find another cygwin DLL.

The error message is puzzling as MSYS2 does not have any cygwin1.dll at all.

How do I fix this? Obviously I don't want to delete the Cygwin installation's cygwin1.dll .

The m2 executable does not have any dependencies other than msys-2.0.dll and built-in Windows DLLs. (I checked with Dependency Walker). It must be something about the binary built with MSYS2 GCC that is meant to search for msys-2.0.dll but instead finds the installed cygwin1.dll. Is there a workaround?

The output of ldd m2.exe is:

    ntdll.dll => /cygdrive/c/Windows/SYSTEM32/ntdll.dll (0x7ffd12740000)
    KERNEL32.DLL => /cygdrive/c/Windows/system32/KERNEL32.DLL (0x7ffd115f0000)
    KERNELBASE.dll => /cygdrive/c/Windows/system32/KERNELBASE.dll (0x7ffd0f2b0000)
    msys-2.0.dll => /c/Temp/msys-2.0.dll (0x180040000)
M.M
  • 138,810
  • 21
  • 208
  • 365
  • 1
    I have a fairly grotty workaround so far: `cmd /c m2.exe` seems to work – M.M Apr 04 '17 at 09:47
  • I suspect that Cygwin has code for detecting whether it is running a Cygwin program, and it does special stuff to set it up when it runs it. It is probably detecting that your msys2 program is a Cygwin program, and this is causing problems because it is not really a Cygwin program. Is there are reason you want to do this? Any reason you can't just compile a native Windows (mingw-w64) program with MSYS2 and then run that from Cygwin? Or just compile your program from source in Cygwin? – David Grayson Apr 04 '17 at 18:12
  • @DavidGrayson Yeah, the thing I'm compiling actually uses some POSIX calls that aren't offered by mingw-w64 ... It might be possible to make it work but it could be a bit of a rabbit hole – M.M Apr 04 '17 at 21:35
  • 1
    Then I'd suggest compiling it from source on Cygwin. Especially since it has no extra library dependencies, that shouldn't be too hard. – David Grayson Apr 04 '17 at 23:25
  • Since you're attempting to run your executable under cygwin, please show the output of running "ldd m2.exe" to see cygwin's idea of dependencies. I think you'd need to set LD_LIBRARY_PATH in order for cygwin to find your dll. – ewindes Apr 06 '17 at 14:05
  • @ewindes added that to question. Setting `export LD_LIBRARY_PATH=/c/Temp` made no difference. – M.M Apr 06 '17 at 21:03
  • 2
    I think that @DavidGrayson's comment is the correct answer. The executable you created with MSYS2 is not meant to run under cygwin. If you want to run there, compile your program under cgywin. – ewindes Apr 06 '17 at 21:28
  • @ewindes well, maybe. Executables created with MSYS2 *do* seem to run under Windows generally, if you deploy the right DLLs. (David even talks in another answer [here](http://stackoverflow.com/questions/42742020/what-files-of-mingw-need-to-be-deployed) about using trial-and-error or dependency walker to figure out which DLLs to deploy). And in general, programs that work in Windows can be launched from Cygwin too. This case seems like an unusual intransitivity. – M.M Apr 06 '17 at 21:37
  • Well, the base issue is that msys-2.0.dll can't be loaded with cygwin1.dll already in memory. It is complaining that "cygheap" isn't at the address it expects to see it. (I think if you run "strings msys-2.0.dll | grep incompat" you'll see that the error message is in that DLL.) Essentially msys-2.0.dll is an (incompatible) version of cygwin1.dll. – ewindes Apr 06 '17 at 22:40
  • Cygwin has a mild incompatibility [between 32-bit and 64-bit versions of itself](https://stackoverflow.com/a/18333049) in that the DLLs are *not* shared and the programs are called in the normal windows way. I don't really see what's preventing it from not doing this for MSYS2 in its code, but maybe I just need to read [`spawn.cc` and `hookapi.cc`](https://github.com/mirror/newlib-cygwin) harder. For one thing, I am sure that the `msys-2.0.dll` rename should have disabled the `cygwin1.dll` detection. – Mingye Wang Jun 08 '20 at 18:31

0 Answers0