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