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

GCC 10编译报错:undefined reference to `std::__throw_bad_array_new_length()`求建议

GCC 10编译时std::__throw_bad_array_new_length()未定义引用错误的解决建议

问题现象

使用GCC 10编译时出现链接错误:

in function `__gnu_cxx::new_allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >::allocate(unsigned long, void const*)':
/usr/include/c++/11/ext/new_allocator.h:116: undefined reference to `std::__throw_bad_array_new_length()'

已做排查

执行命令验证目标库中存在该函数:

objdump -T /usr/lib/gcc/x86_64-redhat-linux/11/libstdc++.so |c++filt|grep throw_bad_array_new_length

输出结果显示函数已定义:

00000000000a41d3 g    DF .text  0000000000000035  GLIBCXX_3.4.29 std::__throw_bad_array_new_length()
00000000000a14ae g    DF .text  0000000000000035  CXXABI_1.3.8 __cxa_throw_bad_array_new_length

解决建议

  • 统一编译工具链版本:当前编译用GCC 10,但链接的是GCC 11的libstdc++.so,版本不匹配导致符号查找失败。直接使用GCC 11编译,或确保链接阶段调用GCC 10的标准库。
  • 显式指定标准库路径:若必须混用版本,编译时添加参数强制链接GCC 10的libstdc++:
    -L/usr/lib/gcc/x86_64-redhat-linux/10 -lstdc++
    
  • 检查编译标准参数:确认编译时指定了正确的C++标准版本(如-std=c++17),避免因标准特性不兼容导致符号缺失。
  • 清理重建项目:删除所有旧的目标文件、编译缓存(如CMakeCache.txt)后重新编译,排除残留产物的版本冲突。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.02 10:32:47