-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


 

 

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐