【问题标题】:How to solve mingw-w64 MSVCRT dependency issues如何解决 mingw-w64 MSVCRT 依赖问题
【发布时间】:2019-11-12 09:51:54
【问题描述】:

我正在使用 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

经过一番研究,我确定这是 mingw64 的 msvcrt 兼容性问题。 我知道有这样的解决方法:unresolved external symbol __imp__fprintf and __imp____iob_func, SDL2 但这并不能解决我所有的问题。

我尝试链接库:LDFLAGS: -L%filepath% -llegacy_stdio_definitions,没有任何变化。

是否有补丁可以修复它,还是我必须构建我的自定义版本的 mingw64?

【问题讨论】:

  • 您是否正在混合来自两个不同工具链的文件,因为这不起作用?
  • @Richard Critten 我为什么要这样做?
  • 因为 mingw-w64 不使用 MSVCRT,它有自己的 C 运行时支持库。所以问题标题提示了我的评论。
  • @RichardCritten 我已经在我的机器上测试过了。即使是一个简单的“hello world”二进制文件,也会在启动时加载msvcrt.dll

标签: c++ go compiler-errors mingw-w64 msvcrt


【解决方案1】:

所以我自己回答我的问题,这个案子已经结案了。

是的,Mingw64 使用 msvcrt。

这里有一些技巧可以帮助解决 Mingw64 和 msvcrt 之间的依赖问题。 主要目标是让编译器加载正确版本的 MSVCRT 库系列。

1.更新 Mingw64。

2.查看Mingw64\include_mingw.h(或x86_64-w64-mingw32\include)中的MSVCRT_VERSION,确保版本号与您的windows版本匹配,或者修改它。

3.看看像“#cgo LDFLAGS: -Lxxx”这样的链接器选项,不要弄乱库路径。删除任何不必要的库路径设置,让链接器自己找到库。

  1. 确保所有内容均使用相同的库构建。

【讨论】:

    猜你喜欢
    • 2017-01-03
    • 1970-01-01
    • 2021-12-02
    • 1970-01-01
    • 2019-09-02
    • 2017-06-24
    • 1970-01-01
    • 2019-06-07
    • 2023-02-21
    相关资源
    最近更新 更多