我有一个项目,我使用-lcblas标志链接到BLAS库。它用于编译,直到将我的系统升级到Ubuntu 18.04和GCC 7.3.0之后。无论如何,编译命令是
g++ -o @$ benchmark.o mine.o -lcblas
产生错误
/usr/bin/x86_64-linux-gnu-ld: benchmark.o: relocation R_X86_64_32 against `.bss' 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
此问题可能重复,但我无法将解决方案转换为其他类似问题。
答案 0 :(得分:2)
制作PIE对象时不能使用;用-fPIC重新编译
Ubuntu 18.04:g ++ - 5(5.5),g ++ - 6,g ++ - 7默认配置为PIE。
使用g++ -no-pie -o ... ..
,或使用g ++ - 4.8:sudo apt install g ++ - 4.8。参考。 How to configure gcc to use -no-pie by default?
Ubuntu 16.04和18.04的额外编译器→“no PIE” g ++ 54 :gcc54-c++_5.4.0-ubuntu16_amd64.deb
→提供/ usr / bin / {gcc54,g ++ 54,gfortran54} 。链接:https://drive.google.com/file/d/1ptHLaZXImpeMzq4xuuGGn5VjrvxNSop3/view?usp=sharing
更多gcc(无PIE)https://drive.google.com/drive/folders/1xVEATaYAwqvseBzYxKDzJoZ4-Hc_XOJm?usp=sharing