重定位被截断以适应使用 g++ 编译时出现的错误

Relocation truncated to fit error when compiling using g++

本文关键字:编译 g++ 错误 定位      更新时间:2023-10-16

我正在尝试在 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)
以前有人遇到过此错误吗?谢谢。

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

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

g++ -mcmodel=medium ....