2021-10-24

GCC 链接 cannot find -lmingwex cannot find -lmsvcrt 等 错误

使用 NASM 写 win32 汇编程序,在使用 gcc 链接时,不断报错,

# 编译命令如下
nasm -f win32 src.asm -l src.lst -o src.obj && gcc src.obj -g -o -o src.exe -m32

CSDN说法都是缺少链接库,但是每一篇文章都没说清除解决方案。

在使用 SASM 自带的 mingw 链接时却是正常,经过检查,发现 SASM 目录下有 mingw 和 mingw64 两个文件夹,故猜测,mingw64 无法链接 32位 程序。使用mingw 32 链接成功运行。

gcc 使用 -m32 或 -m64 可以构建 32位 或 64位 程序,但是需要包含相应的运行库。但是同时装mingw32 和 mingw64 在配置 PATH 时并不能共存,稍显繁琐

遂在网上查得以下资料。

http://stackoverflow.com/questions/19690504/how-do-i-compile-and-link-a-32-bit-windows-executable-using-mingw-w64 That depends on which variant of toolchain you’re currently using. Both DWARF and SEH variants (which come starting from GCC 4.8.0) are only single-target. You can see it yourself by inspecting the directory structure of their distributions, i.e. they contain only the libraries with either 64- and 32-bit addressing, but not both. On the other hand, plain old SJLJ distributions are indeed dual-target, and in order to build 32-bit target, just supply -m32 flag. If that doesn’t work, then just build with i686-w64-mingw32-g++.

想起当初使用 mingw installer 时,选择安装版本时,选的时 seh ,所以造成这个问题。于是去下载了 ljsj 的重新安装。

再次使用 mingw64 编译运行.

成功生成 exe

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值