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

在x64系统编译32位C代码时gcc -m32报错求助

在x64 Ubuntu上编译32位C代码时的链接错误问题

尝试在x64机器上用gcc -m32编译32位C代码时,出现以下链接错误:

pegasus@pegasus:~/Documents/CSE21_workshop$ gcc -m32 got_plt.c 
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/8/libgcc.a when searching for -lgcc
/usr/bin/ld: cannot find -lgcc: No such file or directory
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/8/libgcc.a when searching for -lgcc
/usr/bin/ld: cannot find -lgcc: No such file or directory
collect2: error: ld returned 1 exit status

已安装g++-multilib和gcc-multilib,当前gcc版本为:

pegasus@pegasus:~$ gcc --version
gcc (Ubuntu 8.4.0-3ubuntu2) 8.4.0
Copyright (C) 2018 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

解决方法

  • 安装对应版本的32位libgcc开发库:
    sudo apt-get install libgcc-8-dev:i386
    
  • 若仍有依赖问题,补充安装32位C标准库开发包:
    sudo apt-get install libc6-dev:i386
    
  • 重新执行编译命令(建议指定输出文件名):
    gcc -m32 got_plt.c -o got_plt
    

原因说明

链接器报错是因为仅安装gcc-multilib后,对应的32位版本libgcc库并未自动安装,导致链接时只能找到不兼容的64位库,进而无法完成32位程序的链接。安装对应版本的32位开发库后,链接器就能找到匹配的32位依赖文件。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.20 08:24:55