2011-05-20 51 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 ....