You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

在Ubuntu 24.04.2 LTS上编译MinGW 13.0.0(GCC 15.2)CRT时遭遇configure错误求助

解决MinGW CRT编译时的.scl/.endef汇编伪指令错误

问题描述

我正在Ubuntu 24.04.2 LTS系统上构建适用于Linux的MinGW 13.0.0(搭配GCC 15.2),已完成以下前置步骤:

  • 编译binutils:
    ../configure --target=x86_64-w64-mingw32 --enable-targets=x86_64-w64-mingw32,i686-w64-mingw32
    make -j7
    sudo make install
    
  • 安装头文件:
    sudo mkdir -p /usr/local/x86_64-w64-mingw32/lib
    ../configure --host=x86_64-w64-mingw32 --prefix=/usr/local/x86_64-w64-mingw32
    sudo make install
    sudo ln -s /usr/local/x86_64-w64-mingw32 /usr/local/mingw
    sudo ln -s /usr/local/x86_64-w64-mingw32/lib /usr/local/x86_64-w64-mingw32/lib64
    
  • 编译GCC:
    ../configure --target=x86_64-w64-mingw32 --enable-targets=all
    make all-gcc -j7
    sudo make install-gcc
    

当前尝试编译CRT,执行配置命令:

../configure --host=x86_64-w64-mingw32 --enable-lib32 --prefix=/usr/local/x86_64-w64-mingw32

时出现错误:

configure: error: cannot compute suffix of object files: cannot compile

查看config.log文件,发现以下汇编错误:

/tmp/ccNpE5Ge.s:20: Error: unknown pseudo-op: `.scl'
/tmp/ccNpE5Ge.s:20: Error: Missing symbol name in directive
/tmp/ccNpE5Ge.s:20: Error: unrecognized symbol type "32"
/tmp/ccNpE5Ge.s:20: Error: unknown pseudo-op: `.endef'

我曾尝试为binutils和GCC指定prefix,但问题仍未解决,恳请提供有效的解决思路。


错误原因分析

我之前处理过类似的交叉编译问题,这个错误的核心是配置脚本误用了系统原生的汇编器,而非MinGW的交叉汇编器。.scl和.endef是GNU汇编器(gas)针对Windows目标的特有伪指令,Ubuntu系统默认的as(x86_64-linux-gnu版本)根本不识别这些指令,因此触发报错。

通常导致这个问题的场景有两种:

  • 交叉工具链的路径未被优先加入PATH环境变量,系统原生工具被优先调用;
  • configure脚本未正确检测到交叉工具链,自动选择了系统原生工具。

具体解决步骤

1. 确保交叉工具链路径优先于系统路径

MinGW交叉工具默认安装在/usr/local/bin,先确认交叉汇编器存在:

ls /usr/local/bin/x86_64-w64-mingw32-as

如果能看到该文件,将/usr/local/bin放到PATH最前端,确保交叉工具被优先调用:

export PATH=/usr/local/bin:$PATH

若希望终端重启后仍生效,可将这条命令追加到~/.bashrc文件中。

2. 配置CRT时明确指定交叉工具前缀

直接在configure命令中强制指定要使用的交叉工具,避免脚本自动选择错误:

../configure \
  --build=x86_64-linux-gnu \
  --host=x86_64-w64-mingw32 \
  --enable-lib32 \
  --prefix=/usr/local/x86_64-w64-mingw32 \
  CC=x86_64-w64-mingw32-gcc \
  AS=x86_64-w64-mingw32-as \
  AR=x86_64-w64-mingw32-ar \
  LD=x86_64-w64-mingw32-ld

这里明确指定了编译器、汇编器、归档器、链接器的交叉版本,从根源上避免误用系统工具。

3. 验证交叉编译器是否正常工作

先做一个简单测试,确认交叉工具链功能正常:

echo 'int main() { return 0; }' > test.c
x86_64-w64-mingw32-gcc test.c -o test.exe
file test.exe

如果输出显示PE32+ executable (console) x86-64, for MS Windows,说明交叉工具链工作正常;若报错,可能需要重新编译GCC,检查之前的configure参数是否正确,尤其是--target和安装路径设置。

4. 清理旧配置缓存后重试

如果之前反复执行过configure,可能残留了错误的缓存数据,先清理干净:

make distclean
rm -rf config.cache

之后再重新运行上述带明确工具前缀的configure命令。


内容的提问来源于stack exchange,提问作者Coarse Rosinflower

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.27 12:28:13