【问题标题】:Relocation truncated to fit error when compiling using g++使用 g++ 编译时重定位被截断以适应错误
【发布时间】:2011-08-29 12:10:52
【问题描述】:

我在linux下尝试编译一段cpp代码,报错如下:

/tmp/ccIeh7Ta.o: In function `model::MulPLSA::EStep()':
mul_plsa.cpp:(.text+0xb12): relocation truncated to fit: R_X86_64_32S against symbol `model::MulPLSA::mItemLatRatDeno' defined in .bss section in /tmp/ccIeh7Ta.o
mul_plsa.cpp:(.text+0xb42): relocation truncated to fit: R_X86_64_32S against symbol `model::MulPLSA::mItemLatRatDeno' defined in .bss section in /tmp/ccIeh7Ta.o
/tmp/ccIeh7Ta.o: In function `model::MulPLSA::MStep()':
mul_plsa.cpp:(.text+0xcec): relocation truncated to fit: R_X86_64_32S against symbol `model::MulPLSA::mItemLatRatDeno' defined in .bss section in /tmp/ccIeh7Ta.o
collect2: ld returned 1 exit status

我的操作系统:Ubuntu 10.10
g++:gcc 版本 4.4.5 (Ubuntu/Linaro 4.4.4-14ubuntu5)
以前有人遇到过这个错误吗?谢谢。

【问题讨论】:

  • 博客在中国无效。我google了这个问题,发现编译的时候加上options -mcmodel=medium 可以解决这个问题。我这样做了,编译器抛出警告:/tmp/ccG10FOV.s:3107:警告:忽略 .lbss 的不正确部分类型。无论如何,它有效。
  • 请给我们一个最小的例子。相关:stackoverflow.com/questions/10486116/…

标签: c++ g++ relocation


【解决方案1】:

默认情况下,程序是在小代码模型中生成的,这基本上意味着它的符号必须链接在地址空间的低 2 GB 中。

如果不合适,解决方案可以是使用中等代码模型,这意味着程序和小符号链接在地址空间的较低 2GB 中,而大符号则放入位于 2BG 以上的大数据或 bss 部分(摘自man gcc)。 大符号是使用 -mlarge-data-threshold 定义的,因此可以进行一些优化,但请注意该值在所有对象中应该相同。

g++ -mcmodel=medium ....

【讨论】:

    猜你喜欢
    • 2013-12-25
    • 1970-01-01
    • 2012-01-01
    • 2015-10-20
    • 1970-01-01
    • 2014-08-13
    • 2016-05-01
    • 2016-04-03
    • 1970-01-01
    相关资源
    最近更新 更多