【问题标题】:Linking error with gcc/g++ 7.3.0 on ubuntu 18.04在 ubuntu 18.04 上与 gcc/g++ 7.3.0 链接错误
【发布时间】:2018-10-17 04:39:22
【问题描述】:

我有一个项目,我使用 -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

此问题可能是重复的,但我无法将解决方案翻译为与我的问题类似的其他问题。

【问题讨论】:

  • 嗯,通常这在构建共享库时会出现问题,但在构建常规可执行程序时则不会。你确定你不是在构建 .so 吗?
  • 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 。参考。 stackoverflow.com/questions/49101265/…
  • 请参阅superuser.com/questions/1320425/… ...关于“无 PIE”gcc54-c++_5.4.0-ubuntu16_amd64.deb
  • @n.m. : 我很确定。也就是说,除非幕后发生了一些我不知道的事情。我完全按照我的帖子中写的那样运行命令,我通常只看到 *.o 文件,根本看不到 *.so 文件。
  • @KnudLarsen 传递 -no-pie 参数似乎可以解决问题。构建命令运行没有错误。你会发布我可以接受的回复吗?

标签: c++ linux linker gcc7


【解决方案1】:

制作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 的额外编译器 → “无 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

【讨论】:

  • 不要在随机云上发布随机二进制文件的链接!
猜你喜欢
  • 1970-01-01
  • 2012-01-19
  • 1970-01-01
  • 2017-01-23
  • 2023-04-01
  • 1970-01-01
  • 1970-01-01
  • 2022-09-23
  • 1970-01-01
相关资源
最近更新 更多