Ubuntu下编译报错ld: final link failed: nonrepresentable section on output

-fPIC重新编译,这个问题只有在64位系统中编译的时候才会出现。-fPIC 作用于编译阶段,告诉编译器产生与位置无关代码(Position-Independent Code),则产生的代码中,没有绝对地址,全部使用相对地址,故而代码可以被加载器加载到内存的任意位置,都可以正确的执行。这正是共享库所要求的,共享库被加载时,在内存的位置不是固定的。
解决方法:
如果是cmake ,在CMakeList.txt 前面添加: add_compile_options(-fPIC)

参考:http://www.openskill.cn/question/532

/usr/bin/x86_64-linux-gnu-ld: CMakeFiles/minidbg.dir/ext/linenoise/linenoise.c.o: relocation R_X86_6

[ 22%] Built target hello
fatal: not a git repository (or any of the parent directories): .git
fatal: not a git repository (or any of the parent directories): .git
[ 22%] Built target libelfin
[ 33%] Linking CXX executable minidbg
/usr/bin/x86_64-linux-gnu-ld: CMakeFiles/minidbg.dir/ext/linenoise/linenoise.c.o: relocation R_X86_64_32 against `.rodata' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/x86_64-linux-gnu-ld: final link failed: Nonrepresentable section on output
collect2: error: ld returned 1 exit status
CMakeFiles/minidbg.dir/build.make:100: recipe for target 'minidbg' failed
make[2]: *** [minidbg] Error 1
CMakeFiles/Makefile2:141: recipe for target 'CMakeFiles/minidbg.dir/all' failed
make[1]: *** [CMakeFiles/minidbg.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2


 

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值