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

gcc-12编译报错:More atoms allocated than expected 问题求助

GCC链接器断言失败问题排查

执行g++ file.cpp时触发以下ld链接器断言错误:

0  0x1008a81a0  __assert_rtn + 140
1  0x10072fa8c  mach_o::relocatable::Parser<arm64>::parse(mach_o::relocatable::ParserOptions const&) + 4536
2  0x100701d38  mach_o::relocatable::Parser<arm64>::parse(unsigned char const*, unsigned long long, char const*, long, ld::File::Ordinal, mach_o::relocatable::ParserOptions const&) + 148
3  0x10076a4ac  ld::tool::InputFiles::makeFile(Options::FileInfo const&, bool) + 1468
4  0x10076d360  ___ZN2ld4tool10InputFilesC2ER7Options_block_invoke + 56
5  0x18c69c1f4  _dispatch_client_callout2 + 20
6  0x18c6b0f8c  _dispatch_apply_invoke_and_wait + 224
7  0x18c6b026c  _dispatch_apply_with_attr_f + 1152
8  0x18c6b047c  dispatch_apply + 108
9  0x10076d1f4  ld::tool::InputFiles::InputFiles(Options&) + 616
10  0x1006ef6c0  main + 552
A linker snapshot was created at:
    /tmp/a.out-2022-09-15-161557.ld-snapshot
ld: Assertion failed: (_file->_atomsArrayCount == computedAtomCount && "more atoms allocated than expected"), function parse, file macho_relocatable_file.cpp, line 2061.
collect2: error: ld returned 1 exit status

已尝试卸载重装gcc、Xcode Command Line Tools和Xcode,问题仍未解决;代码可在Xcode中正常编译,仅gcc编译时出现该错误。

解决方案

  • 验证gcc架构兼容性
    运行gcc -v查看版本信息,确认是否适配Apple Silicon(arm64)架构。若为x86_64版本,通过Homebrew安装适配arm64的gcc:brew install gcc。

  • 显式指定Xcode链接器
    编译时强制使用Xcode自带的ld链接器,执行命令:

    g++ file.cpp -fuse-ld=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld
    
  • 清理缓存文件

    • 删除Xcode衍生数据:rm -rf ~/Library/Developer/Xcode/DerivedData
    • 删除链接器快照临时文件:rm -rf /tmp/*ld-snapshot*
  • 排查架构相关代码
    检查代码中是否包含仅适配Xcode编译流程的arm64架构特定指令(如内嵌汇编),这类代码可能导致gcc生成的目标文件与系统链接器不兼容。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.19 09:20:20