简体   繁体   English

如何解决 mingw-w64 MSVCRT 依赖问题

[英]How to solve mingw-w64 MSVCRT dependency issues

I'm building a golang project by using Go1.12 + msys2/mingw-w64(9.2.0), it shows errors:我正在使用 Go1.12 + msys2/mingw-w64(9.2.0) 构建一个 golang 项目,它显示错误:

D:\Go\pkg\tool\windows_amd64\link.exe: running gcc failed: exit status 1
D:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/lib/../lib/crt2.o: in function `pre_c_init':
E:/mingwbuild/mingw-w64-crt-git/src/mingw-w64/mingw-w64-crt/crt/crtexe.c:146: undefined reference to `__p__fmode'
D:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/lib/../lib/crt2.o: in function `__tmainCRTStartup':
E:/mingwbuild/mingw-w64-crt-git/src/mingw-w64/mingw-w64-crt/crt/crtexe.c:290: undefined reference to `_set_invalid_parameter_handler'
D:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: E:/mingwbuild/mingw-w64-crt-git/src/mingw-w64/mingw-w64-crt/crt/crtexe.c:299: undefined reference to `__p__acmdln'
D:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/lib/../lib/libmingw32.a(lib64_libmingw32_a-merr.o): in function `_matherr':
E:/mingwbuild/mingw-w64-crt-git/src/mingw-w64/mingw-w64-crt/crt/merr.c:46: undefined reference to `__acrt_iob_func'
D:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/lib/../lib/libmingw32.a(lib64_libmingw32_a-pseudo-reloc.o): in function `__report_error':
E:/mingwbuild/mingw-w64-crt-git/src/mingw-w64/mingw-w64-crt/crt/pseudo-reloc.c:149: undefined reference to `__acrt_iob_func'
D:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: E:/mingwbuild/mingw-w64-crt-git/src/mingw-w64/mingw-w64-crt/crt/pseudo-reloc.c:150: undefined reference to `__acrt_iob_func'
collect2.exe: error: ld returned 1 exit status

After some research I'm sure it's a msvcrt compatibility issue of mingw64.经过一番研究,我确定这是 mingw64 的 msvcrt 兼容性问题。 I know there are workarounds like this: unresolved external symbol __imp__fprintf and __imp____iob_func, SDL2 But it doesn't solve all of my issues.我知道有这样的解决方法: 未解析的外部符号 __imp__fprintf 和 __imp____iob_func, SDL2但它并不能解决我的所有问题。

I try to link the library: LDFLAGS: -L%filepath% -llegacy_stdio_definitions, nothing changes.我尝试链接库:LDFLAGS:-L%filepath% -llegacy_stdio_definitions,没有任何变化。

Is there a patch to fix it, or do I have to build my custom version of mingw64?是否有修复它的补丁,或者我必须构建我的自定义版本的 mingw64?

So I answer my question by myself, the case is closed.所以我自己回答我的问题,这个案子已经结案了。

Yes, Mingw64 uses msvcrt.是的,Mingw64 使用 msvcrt。

Here are some tips that could help to solve dependency problems between Mingw64 & msvcrt.这里有一些技巧可以帮助解决 Mingw64 和 msvcrt 之间的依赖问题。 The major goal is to let compiler load the correct version of MSVCRT library family.主要目标是让编译器加载正确版本的 MSVCRT 库系列。

1.Update Mingw64. 1.更新Mingw64。

2.Check out MSVCRT_VERSION in Mingw64\include_mingw.h(or x86_64-w64-mingw32\include), make sure the version number matches your windows version, or modify it. 2.查看Mingw64 \include_mingw.h(或x86_64-w64-mingw32\include)中的MSVCRT_VERSION,确保版本号与您的windows版本匹配,或修改它。

3.Take a look at linker option like "#cgo LDFLAGS: -Lxxx", don't mess the library path. 3.看看linker选项,比如“#cgo LDFLAGS: -Lxxx”,不要弄乱库路径。 Remove any unnecessary library path setting, let linker finds libraries itself.删除任何不必要的库路径设置,让 linker 自己找到库。

  1. Make sure everything is built with same libraries.确保一切都是用相同的库构建的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM