【发布时间】:2022-11-13 17:50:42
【问题描述】:
我的程序使用了一些包含 POSIX 函数调用并且不能用 MinGW 编译的库,我将 Qt6 用于 MinGW(没有 Qt6 用于 cygwin 或 msys2)。所以我需要让我的程序链接到由cygwin构建的dll。它链接成功,但无法运行。
例如,这里有两个文件a.c和b.c:
/* a.c */
int a() {
return 1;
}
/* b.c */
extern int a();
int main() {
return a();
}
我使用 cygwin 将 a.c 编译为 a.dll:
(In cygwin shell)
$ gcc -c a.c -o a.o
$ gcc -shared a.o -o a.dll
$ ldd a.dll
ntdll.dll => /cygdrive/c/Windows/SYSTEM32/ntdll.dll (0x7ff9d5450000)
KERNEL32.DLL => /cygdrive/c/Windows/System32/KERNEL32.DLL (0x7ff9d50f0000)
KERNELBASE.dll => /cygdrive/c/Windows/System32/KERNELBASE.dll (0x7ff9d2e90000)
msvcrt.dll => /cygdrive/c/Windows/System32/msvcrt.dll (0x7ff9d5370000)
cygwin1.dll => /cygdrive/c/Users/notify/Documents/cygwin1.dll (0x180040000)
advapi32.dll => /cygdrive/c/Windows/System32/advapi32.dll (0x7ff9d3b70000)
sechost.dll => /cygdrive/c/Windows/System32/sechost.dll (0x7ff9d3c20000)
RPCRT4.dll => /cygdrive/c/Windows/System32/RPCRT4.dll (0x7ff9d51b0000)
CRYPTBASE.DLL => /cygdrive/c/Windows/SYSTEM32/CRYPTBASE.DLL (0x7ff9d2440000)
bcryptPrimitives.dll => /cygdrive/c/Windows/System32/bcryptPrimitives.dll (0x7ff9d2b50000)
然后我使用 MinGW 编译 b.c 并将其链接到 a.dll:
(In MSYS2 MINGW64 shell)
$ gcc -c b.c -o b.o
$ gcc b.o -L. a.dll -o b.exe
$ ldd b.exe
ntdll.dll => /c/Windows/SYSTEM32/ntdll.dll (0x7ff9d5450000)
KERNEL32.DLL => /c/Windows/System32/KERNEL32.DLL (0x7ff9d50f0000)
KERNELBASE.dll => /c/Windows/System32/KERNELBASE.dll (0x7ff9d2e90000)
msvcrt.dll => /c/Windows/System32/msvcrt.dll (0x7ff9d5370000)
a.dll => /c/Users/notify/Documents/a.dll (0x5e4da0000)
cygwin1.dll => /c/Users/notify/Documents/cygwin1.dll (0x180040000)
$ ./b.exe
0 [main] b (1828) C:\Users\notify\Documents\b.exe: *** fatal error - cygheap base mismatch det
ected - 0x180350408/0x18034C408.
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.
我怎么解决这个问题?
【问题讨论】: