【问题标题】:gcc compile error: /usr/bin/ld: gfx.o: relocation R_X86_64_32 against `.rodata' can not be used when making a PIE object; recompile with -fPIEgcc 编译错误:/usr/bin/ld: gfx.o: 在制作 PIE 对象时不能使用针对 .rodata 的重定位 R_X86_64_32;使用 -fPIE 重新编译
【发布时间】:2022-12-10 06:05:18
【问题描述】:

错误如下:

/usr/bin/ld: gfx.o: relocation R_X86_64_32 against `.rodata' can not be used when making a PIE object; recompile with -fPIE
/usr/bin/ld: failed to set dynamic section sizes: bad value
collect2: error: ld returned 1 exit status
make: *** [Makefile:4: project] Error 1

当我添加 -fPIC-fPIE 时,没有任何变化。我知道 gfx.o 库可以工作,因为它以前可以工作,并且当我在我的服务器上使用 ssh 时它仍然可以工作。

制作文件如下:

project: project.c
  gcc project.c gfx.o -lx11 -lm -fPIE -o -project
clean:
  rm project

我尝试在 makefile 中使用 -fPIE-fPIC。我还尝试卸载并重新安装 gcc 和 binutills,但没有任何效果。

【问题讨论】:

  • 重新编译 -fPIE ...
  • 我已经尝试过了,但它仍然显示相同的提示。
  • don't post images of text。复制粘贴文本作为文本进入你的问题。
  • 至于您的问题,您可以将实际的错误消息复制并粘贴到您最喜欢的搜索引擎中,您应该会得到大量的点击率来解释您为什么会收到它以及如何解决它。哎呀,如果你看这个问题的右侧,在“相关”部分下,你会发现这个网站上有很多关于它的问题。
  • 您已将 -fPIE 添加到编译 project.c 并将其链接到的链接行。但是错误消息清楚地表明问题出在 gfx.o,而不是 project.c,并且您没有做任何事情makefile 指定你需要用-fPIE构建gfx.o

标签: c gcc makefile compiler-errors fpic


【解决方案1】:

我发现将 -no-pie 放在 Makefile 中可以解决问题。我不知道是否有更永久和更广泛的修复,但它有效。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-03-31
    • 2017-07-22
    • 1970-01-01
    • 2023-01-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多