2011-05-20 52 views
2

我试图编译一块linux下cpp的代码编译时以适应错误,并得到了以下错误:搬迁截断使用G ++

/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)
任何人都遇到过这个错误?谢谢。

+0

看http://amiatypist.blogspot.com/2010/05/relocation-truncated-to-fit-rx866432s.html可能是有用的... – fritzone 2011-05-20 10:33:29

+1

的blogspot在中国无效。我谷歌这个问题,并发现在编译时添加选项-mcmodel =中可以解决这个问题。我这样做了,编译器抛出了一个waring:/tmp/ccG10FOV.s:3107:警告:忽略.lbss的不正确的节类型。无论如何,它的作品。 – user572138 2011-05-20 10:41:21

+0

请给我们一个简单的例子。相关:http://stackoverflow.com/questions/10486116/what-does-this-gcc-error-relocation-truncated-to-fit-mean – 2015-09-03 21:24:09

回答

1

只需补充以上的答案:

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

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

g++ -mcmodel=medium ....