0

I wrote some simple application in C (for test) - GCC 9.3.0 on CYGWIN (x86_64-pc-cygwin) on Windows 10. And it worked fine. But 1-2 days ago Windows 10 was updated (Feature Update 1909 (2)). I dont know is the update a reason of the next error, but now the application can sometimes work, but more often it fails with an error:

$ ./xxx.exe
      0 [main] xxx (7152) D:\prj\xxx\xxx.exe: *** fatal error - cygheap base mismatch detected - 0x180343408/0x1093408.
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.

This happens when it's running in the Cygwin console (bash) - Cygwin.bat. I dont see strange things in the bash environment. But it always works fine being running in the PowerShell (cygwin1.dll is in the same folder as the app). ldd xxx.exe in the Cygwin's bash shows:

$ ldd xxx.exe
        ntdll.dll => /cygdrive/c/WINDOWS/SYSTEM32/ntdll.dll (0x7fff5e440000)
        KERNEL32.DLL => /cygdrive/c/WINDOWS/System32/KERNEL32.DLL (0x7fff5da50000)
        KERNELBASE.dll => /cygdrive/c/WINDOWS/System32/KERNELBASE.dll (0x7fff5b860000)
        cygwin1.dll => /cygdrive/d/prj/xxx/cygwin1.dll (0xcc0000)
        FreeImage.dll => /cygdrive/d/prj/xxx/FreeImage.dll (0x180000000)
        WS2_32.dll => /cygdrive/c/WINDOWS/System32/WS2_32.dll (0x7fff5d870000)
        VCOMP140.DLL => /cygdrive/c/WINDOWS/SYSTEM32/VCOMP140.DLL (0x7fff55550000)
        RPCRT4.dll => /cygdrive/c/WINDOWS/System32/RPCRT4.dll (0x7fff5d750000)
        USER32.dll => /cygdrive/c/WINDOWS/System32/USER32.dll (0x7fff5e0b0000)
        win32u.dll => /cygdrive/c/WINDOWS/System32/win32u.dll (0x7fff5bd40000)
        GDI32.dll => /cygdrive/c/WINDOWS/System32/GDI32.dll (0x7fff5cac0000)
        gdi32full.dll => /cygdrive/c/WINDOWS/System32/gdi32full.dll (0x7fff5b570000)
        msvcp_win.dll => /cygdrive/c/WINDOWS/System32/msvcp_win.dll (0x7fff5b3d0000)
        ucrtbase.dll => /cygdrive/c/WINDOWS/System32/ucrtbase.dll (0x7fff5b470000)
        cygwin1.dll => /cygdrive/d/prj/xxx/cygwin1.dll (0xec0000)

I build the app with:

...
CC = d:/apps/cygwin/gcc
LIBS := libFreeImage.a
...
$(EXE): $(OBJECTS) $(HEADERS)
    $(CC) $(CFLAGS) $(OBJECTS) -o $(EXE) $(LIBS)

What's wrong here? Where can there be the error?

RandomB
  • 3,367
  • 19
  • 30
  • Does this answer your question? [Cygwin/Git error cygheap base mismatch detected](https://stackoverflow.com/questions/8107319/cygwin-git-error-cygheap-base-mismatch-detected) – T.Todua May 22 '23 at 14:52

1 Answers1

1

rm /cygdrive/d/prj/xxx/cyg*.dll and the problem will likely go away.

That is, you have a rogue copy of cygwin1.dll (and probably other cygwin binaries) in your d:\prj\xxx\ directory that are incompatible with your current install of cygwin. (Or some other variation of DLL hell).

Typically when running your code from within the cygwin shell, you just rely on the cygwin DLLs to be loaded by default from /usr/bin instead of from the LDPATH, PATH, or local directory.

Then to distribute your EXE to non-cygwin users (or to simply run your EXE outside of the Cygwin shell), you package up the EXE and all the dependent DLLs together into the same folder. The way you have it, you appear to be mixing and matching DLL locations within the Cygwin environment and your source code path.

Then to run back on a Windows command line parameter, package up your EXE and cygwin1.dll back into the same folder.

And to erase any other doubts, just rebuild your code and update Cygwin to the latest.

selbie
  • 100,020
  • 15
  • 103
  • 173
  • I got this cygwin1.dll from the cygwin folder - just copied it from its folder. And it works under PowerShell - how is it possible?! Also it works for first run, then it begins to fail. Actually I cannot understand such behavior. OK, I will test your suggestion, if it's the fix, I will approve the answer. Thanks! PS. I updated cygwin from different "Download Sites" and sometimes I get error "your list... is newer..."... maybe I broke cygwin installation. – RandomB Apr 17 '20 at 06:14
  • strange. I reinstalled cygwin (from one mirror). Then I cleared all .o, .exe, rebuild app - the same error. I copied cygwin1.dll to app's dir - and sometimes it works, sometimes no. After set/uset LDPATH, I found that it fails once, then it starts to work. Now it mostly works. Maybe it's some effect from Windows Defender? OK, let's think that it's something local on my PC (maybe an effect from Windows update?) :) – RandomB Apr 17 '20 at 06:53
  • I doubt Windows Update or Defender had anything to do with this. The fact that you had an LDPATH to begin with - most definitely. :) – selbie Apr 17 '20 at 07:05
  • *Search for cygwin1.dll using the Windows Start->Find/Search facility and delete all but the most recent version.* - did you actually do this step? – selbie Apr 17 '20 at 07:06